Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Integer.parseInt() Not Working for Large Numbers

I have the following simple piece of code which is intended to detect that a given IPv4 address indeed only has numeric values (that is after the dots have been stripped):

import edu.gcc.processing.exceptions.net.IPAddressNumericException;

//Get the IP address
  String address = "239.255.255.255";

//Check to see if this is a number      
  try {
    String IPNumbers = address.replace(".", "");
    Integer.parseInt(IPNumbers);            
  } catch (NumberFormatException e) {
    System.out.print(e.getMessage());
  }

For some reason, the NumberFormatException is fired, and I get this error:

For input string: "239255255255"

Could someone please help me understand this? The parseInt() method works on smaller numbers, such as 127001.

Thank you for your time.

like image 970
Oliver Spryn Avatar asked Nov 27 '22 11:11

Oliver Spryn


1 Answers

try using Long.parseLong(IPNumbers)

like image 159
PTBG Avatar answered Dec 07 '22 01:12

PTBG