Extract digits from a string in Java

You can use regex and delete non-digits.

str = str.replaceAll("\\D+","");

Leave a Comment