您可以使用正则表达式尝试此方法。
public static int parseWithDefault(String s, int defaultVal) { return s.matches("-?\d+") ? Integer.parseInt(s) : defaultVal; }
您可以使用正则表达式尝试此方法。
public static int parseWithDefault(String s, int defaultVal) { return s.matches("-?\d+") ? Integer.parseInt(s) : defaultVal; }