通过查看java.lang.Integer的源码可以发现, 它们最终调用的都是

/**
* Parses the string argument as a signed integer in the radix
* specified by the second argument. The characters in the string
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
* ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to
* indicate a negative value or an ASCII plus sign {@code '+'}
* (<code>'\u002B'</code>) to indicate a positive value. The
* resulting integer value is returned.
*
* <p>An exception of type {@code NumberFormatException} is
* thrown if any of the following situations occurs:
* <ul>
* <li>The first argument is {@code null} or is a string of
* length zero.
*
* <li>The radix is either smaller than
* {@link java.lang.Character#MIN_RADIX} or
* larger than {@link java.lang.Character#MAX_RADIX}.
*
* <li>Any character of the string is not a digit of the specified
* radix, except that the first character may be a minus sign
* {@code '-'} (<code>'\u002D'</code>) or plus sign
* {@code '+'} (<code>'\u002B'</code>) provided that the
* string is longer than length 1.
*
* <li>The value represented by the string is not a value of type
* {@code int}.
* </ul>
*
* <p>Examples:
* <blockquote><pre>
* parseInt("0", 10) returns 0
* parseInt("473", 10) returns 473
* parseInt("+42", 10) returns 42
* parseInt("-0", 10) returns 0
* parseInt("-FF", 16) returns -255
* parseInt("1100110", 2) returns 102
* parseInt("2147483647", 10) returns 2147483647
* parseInt("-2147483648", 10) returns -2147483648
* parseInt("2147483648", 10) throws a NumberFormatException
* parseInt("99", 8) throws a NumberFormatException
* parseInt("Kona", 10) throws a NumberFormatException
* parseInt("Kona", 27) returns 411787
* </pre></blockquote>
*
* @param s the {@code String} containing the integer
* representation to be parsed
* @param radix the radix to be used while parsing {@code s}.
* @return the integer represented by the string argument in the
* specified radix.
* @exception NumberFormatException if the {@code String}
* does not contain a parsable {@code int}.
*/
public static int parseInt(String s, int radix)
throws NumberFormatException {
}

这个parseInt是可以将字符串解析为各种进制的整数的, parseInt(String s)只是radix=10时的特例

而Integer.parseInt() 和 Integer.valueOf() 的区别主要在于放回的类型上, 一个是 int, 一个是Integer, 如果需要的是int, 性能上parseInt()会好点

    public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
}

这里面调用的是 valueOf(int i) 方法, 其源码中为 -128 ~ 128 之间的Integer对象很贴心地做了缓存以提高效率

    public static Integer valueOf(int i) {
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}

最新文章

  1. Ajax商品分类三级联动实现
  2. 高性能JavaScript(您值得一看)
  3. Redis redis-cli常用操作
  4. jenkins和docker 在docker里运行jenkins
  5. inline-block使标签间出现空白
  6. Windows下一些配置信息
  7. 48. Rotate Image
  8. centos 给鼠标右击添加 “打开终端” 菜单项
  9. hdu_5883_The Best Path(欧拉路)
  10. First release of mlrMBO - the toolbox for (Bayesian) Black-Box Optimization
  11. 深入理解viewport
  12. Java main方法全解
  13. 一次故障解决过程梳理:mysql varchar text timestamp
  14. Spring Cloud项目之断路器集群监控Hystrix Dashboard
  15. style1
  16. 模块——Getopt::Long接收客户命令行参数和Smart::Comments输出获得的命令行参数内容
  17. shell IF分支判断语句
  18. hdu3336 Count the string 扩展KMP
  19. 【HNOI2016】矿区
  20. docker maven 出错:Failed to execute goal com.spotify:docker-maven-plugin:...: Request error: POST https://192.168.99.100:2376/build?t=

热门文章

  1. Android 调用系统照相机拍照和录像
  2. AES加密解密
  3. 【代码笔记】iOS-提醒时间的选择
  4. __block和__weak的区别
  5. eclipse编码格式设置
  6. 关于PHP的curl开启问题
  7. android 进程间通信数据(一)------parcel的起源
  8. WPF学习之路(十一)布局(续)
  9. Vmware快速安装linux虚拟机(SUSE)
  10. HBase应用开发回顾与总结系列之三:RowKey行键生成器工具