Java tutorial
//package com.java2s; public class Main { public static String cleanBlankToString(String des) { char[] chars = des.toCharArray(); StringBuffer sb = new StringBuffer(); for (Character c : chars) { if (java.util.regex.Pattern.matches("\\d", String.valueOf(c))) { sb.append(c); } } return sb.toString(); } }