Integer.parse(String str) java.lang.NumberFormatException: Errors

前端 未结 8 1636
一整个雨季
一整个雨季 2020-12-11 22:18

I keep getting number format expectations, even though I\'m trimming the strings and they don\'t contain non numerical characters bizarrely it works for some numbers and not

8条回答
  •  渐次进展
    2020-12-11 23:11

        String n="3020857508";
        Long l = Long.parseLong(n.trim());
        System.out.println(l);
    

    Integer MAX_VALUE : 2147483647, Long MAX_VALUE : 9223372036854775807

    As string n will not fit in Integer after conversion we have to use Long.

    And if you are still not sure about range that can come in String. go with BigIntegerwhere number is held in an int[]

提交回复
热议问题