public static String stripNonDigits(String str){
  StringBuffer result=new StringBuffer(str.length());
  for (  char candidate : str.toCharArray()) {
    if (Character.isDigit(candidate)) {
      result.append(candidate);
    }
  }
  return result.toString();
}

public static String stripNonDigits ( String str ) { StringBuffer result = new StringBuffer ( str . length ( ) ) ; for ( char candidate : str . toCharArray ( ) ) { if ( Character . isDigit ( candidate ) ) { result . append ( candidate ) ; } } return result . toString ( ) ; }
strips all non - digit characters from a string . the resulting string will only contain characters for which isdigit ( ) returns true .
