📌  相关文章
📜  如何在java代码示例中检查是否可以解析整数

📅  最后修改于: 2022-03-11 14:52:37.985000             🧑  作者: Mango

代码示例2
// if parse is possible then it will do it otherwise compiler 
// will throw exceptions and it is a bad practice to catch all exceptions
// in this case only NumberFormatException happens
public boolean isInteger(String string) {
    try {
        Integer.valueOf(string);
        // Integer.parse(string) /// it can also be used
        return true;
    } catch (NumberFormatException e) {
        return false;
    }
}