Here you can find the source of isNumber(String str)
public static boolean isNumber(String str)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isNumber(String str) { if (isNull(str)) { return false; }//from ww w. j av a2s . c o m Pattern p = Pattern .compile(new StringBuilder("[-]?+[0-9]{").append((str.length() == 0 ? 1 : str.length() - 1)) .append(",").append(str.length()).append("}").toString()); Matcher m = p.matcher(str); return m.matches(); } public static boolean isNull(String str) { return (str == null || str.trim().length() == 0); } }