test if string is float java

Solutions on MaxInterview for test if string is float java by the best coders in the world

showing results for - "test if string is float java"
Liam
03 Jan 2017
1public static void main(String[] args) {
2    String str = "5588";
3    //check if int
4    try{
5        Integer.parseInt(str);
6    }catch(NumberFormatException e){
7        //not int
8    }
9    //check if float
10    try{
11        Float.parseFloat(str);
12    }catch(NumberFormatException e){
13        //not float
14    }
15}
16