String s = ""; if (s.matches("\\d+")) { System.out.println("整数"); } else { System.out.println("非整数"); }