how to check value is string or not in java code example
Example 1: test if string is float java
public static void main(String[] args) {
String str = "5588";
//check if int
try{
Integer.parseInt(str);
}catch(NumberFormatException e){
//not int
}
//check if float
try{
Float.parseFloat(str);
}catch(NumberFormatException e){
//not float
}
}
Example 2: java check if string is number
try {
int n = Integer.parseInt(str);
} catch (NumberFormatException e) {
// str is not a number
}