String s1 = "a"; Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(s1); if (isNum.matches()) { int h = Integer.parseInt(s1); System.out.println(h); } else { System.out.println("不是数字!"); }
原文:http://www.cnblogs.com/214829qw/p/5124005.html