Java Integer.parseInt()不适用于大数字 [英] Java Integer.parseInt() Not Working for Large Numbers
本文介绍了Java Integer.parseInt()不适用于大数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下简单的代码,用于检测给定的IPv4地址确实只有数值(即在剥离点后):
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());
}
出于某种原因, NumberFormatException
被解雇,我收到此错误:
For some reason, the NumberFormatException
is fired, and I get this error:
For input string: "239255255255"
有人可以帮我理解这个吗? parseInt()
方法适用于较小的数字,例如 127001
。
Could someone please help me understand this? The parseInt()
method works on smaller numbers, such as 127001
.
感谢您的时间。
推荐答案
尝试使用 Long.parseLong(IPNumbers)
这篇关于Java Integer.parseInt()不适用于大数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文