给出一种最简单的正则匹配
public static boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
当然这并不是最完美的,最完美的应该是这样
private static final Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
public static boolean isInteger(String str) {
return pattern.matcher(str).matches();
}