Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #parsing #integer #java
ADD COMMENT
Topic
Name
5+3 =