Converting String to int in Java and getting a NumberFormatException, can't figure out why
Posted
by
user1687682
on Stack Overflow
See other posts from Stack Overflow
or by user1687682
Published on 2012-09-21T03:24:22Z
Indexed on
2012/09/21
3:37 UTC
Read the original article
Hit count: 200
ipString is a String representation of an IP address with spaces instead of dots.
String[] ipArray = ipString.split(" ");
String ip = "";
for (String part : ipArray){
if (part != null){
ip += part
}
}
ip = ip.trim();
int ipInt = Integer.parseInt(ip); // Exception is thrown here.
Exception in thread "main" java.lang.NumberFormatException: For input string: "6622015176
".
Could someone explain why this exception is being thrown?
© Stack Overflow or respective owner