Answers for "java check if a string is an integer"

8

java test if a string is a int

public static boolean isInt(String str) {
	
  	try {
      	@SuppressWarnings("unused")
    	int x = Integer.parseInt(str);
      	return true; //String is an Integer
	} catch (NumberFormatException e) {
    	return false; //String is not an Integer
	}
  	
}
Posted by: Guest on May-28-2020
0

java how to check string is number

public static boolean isNumeric(String strNum) {
    if (strNum == null) {
        return false;
    }
    try {
        double d = Double.parseDouble(strNum);
    } catch (NumberFormatException nfe) {
        return false;
    }
    return true;
}
Posted by: Guest on August-10-2021
0

determine if is string or int

string str = "3257fg";
for(int i = 0;i < (strlen(str) - 1);i++) {
    if((int)str[i] < 10) {
        // it is a number, so do some code
    } else {
        // it is not a number, do something else
    }
}
Posted by: Guest on September-23-2021

Code answers related to "java check if a string is an integer"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language