Java tutorial
//package com.java2s; public class Main { private static String getDigitsOnly(String s) { StringBuffer digitsOnly = new StringBuffer(); char c; for (int i = 0; i < s.length(); i++) { c = s.charAt(i); if (Character.isDigit(c)) { digitsOnly.append(c); } } return digitsOnly.toString(); } }