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
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 BigInteger
where number is held in an int[]
In Java, the integer range is from -2,147,483,648 to 2,147,483,647 make sure your numeric value is between the same.