Answers for "check if data could be integer.parsed java"

0

how to check if parsing in integer is possible in java

// 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;
    }
}
Posted by: Guest on May-30-2021
0

how to check if parsing in integer is possible in java

// 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;
    }
}
Posted by: Guest on May-30-2021

Code answers related to "check if data could be integer.parsed java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language