English 中文(简体)
Cannot transformation String to Integer in Java [duplicate]
原标题:Cannot convert String to Integer in Java [duplicate]
  • 时间:2010-08-18 23:56:48
  •  标签:
  • java

我已写了一份功能,将体力转换为愤怒。

   if ( data != null )
   {
        int theValue = Integer.parseInt( data.trim(), 16 );
        return theValue;
   }
   else
       return null;

我有6042076399号指示,给我留下错误:

Exception in thread "main" java.lang.NumberFormatException: For input string: "6042076399"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:461)

这难道不是将扼杀变成愤怒的正确方法吗?

最佳回答

在此,我更喜欢这样做:

Edit(08/04/2015):

如以下评论所述,这实际上做得更好:

String numStr = "123";
int num = Integer.parseInt(numStr);
问题回答

<>Integer>Integer可持有该数值。 6042076399 (4134 24640921 in decimal)大于2147483647,最高可持有该值。

Try using Long.parseLong.

这符合正确的方法,但贵方的价值大于<条码>的上限。

int的最高限额为231- 1, or 2,147,483,647。 你的价值为6 042 076 399。 如果你想要某种原始类型的话,那么你就应当把它作为<条码>长期<>。 长期的最高价值大得多——263——1. 另一种选择可能是BigInteger

这种扼杀大于Integer。 页: 1 你们可以把那些不属于各种愤怒的事物 par起来。 (一至2^31-1,我认为)。

除其他人回答的情况外,如果你有超过8位六位数(但最多为16位六位数),你可以将其改为长期使用<代码>Long.parseLong(,而不是使用Integer.parseInt()。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签