Java examples for java.lang:char
remove Non Digits
//package com.java2s; public class Main { public static void main(String[] argv) { String text = "java2s.com"; System.out.println(removeNonDigits(text)); }/* ww w. j ava 2 s.c o m*/ public static String removeNonDigits(String text) { if (text == null) return null; StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { if (Character.isDigit(text.charAt(i))) { sb.append(text.charAt(i)); } } return sb.toString(); } }