【java 中这两个方法区别在哪里?只是转数据的时候的范围问题吗?】integer.parseint() 与Long.parselong()的区别
在开发中碰到前者在我的机器上能运行,但是到了客户的机器上就不能正常运行了,换成后者的方法就可以了,为什么?
参考API Specification,看看是不是以下情况。
An exception of type NumberFormatException is thrown if any of the following situations occurs:
- The first argument is null or is a string of length zero.
- The radix is either smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX.
- Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') or plus sign '+' ('\u002B') provided that the string is longer than length 1.
- The value represented by the string is not a value of type int.
或者说Integer.MAX_VALUE
是2147483647,Integer.parseInt
会将字符串解析为有符号整型,但如果要转比如F0F0F0F0,超出范围就没得搞。