1.Integer.parseInt():

public static int parseInt(String s) throws NumberFormatException {
return parseInt(s,10);
}
public static int parseInt(String s, int radix) throws NumberFormatException{
/*
* WARNING: This method may be invoked early during VM initialization
* before IntegerCache is initialized. Care must be taken to not use
* the valueOf method.
*/
if (s == null) {
throw new NumberFormatException("null");
} if (radix < Character.MIN_RADIX) {
throw new NumberFormatException("radix " + radix +" less than Character.MIN_RADIX");
} if (radix > Character.MAX_RADIX) {
throw new NumberFormatException("radix " + radix +" greater than Character.MAX_RADIX");
} int result = 0;
boolean negative = false;
int i = 0, len = s.length();
int limit = -Integer.MAX_VALUE;
int multmin;
int digit; if (len > 0) {
char firstChar = s.charAt(0);
if (firstChar < '0') { // Possible leading "+" or "-"
if (firstChar == '-') {
negative = true;
limit = Integer.MIN_VALUE;
} else if (firstChar != '+')
throw NumberFormatException.forInputString(s); if (len == 1) // Cannot have lone "+" or "-"
throw NumberFormatException.forInputString(s);
i++;
}
multmin = limit / radix;
while (i < len) {
// Accumulating negatively avoids surprises near MAX_VALUE
digit = Character.digit(s.charAt(i++),radix); //传入一个字符参数和基数,返回一个int值
if (digit < 0) {
throw NumberFormatException.forInputString(s);
}
if (result < multmin) {
throw NumberFormatException.forInputString(s);
}
result *= radix;
if (result < limit + digit) {
throw NumberFormatException.forInputString(s);
}
result -= digit;
}
} else {
throw NumberFormatException.forInputString(s);
}
return negative ? result : -result;
}

2.Integer.valueOf():

public static Integer valueOf(String s) throws NumberFormatException {
return Integer.valueOf(parseInt(s, 10));
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. GIT 操作
  2. Android Paint类方法说明
  3. 这个算asp.net的一个bug吗?
  4. Redis应用案例,查找某个值的范围(转)
  5. ios之点语法
  6. aix i节点
  7. Android 真机调试显示offline
  8. 在.csproj文件中增加npm, bower, gulp, webpack的构建
  9. AI佳作解读系列(二)——目标检测AI算法集杂谈:R-CNN,faster R-CNN,yolo,SSD,yoloV2,yoloV3
  10. 纯CSS画的基本图形(圆形、三角形、多边形、爱心、八卦等)
  11. JavaScript深入之从原型到原型链
  12. Linux下的at定时执行任务命令详解
  13. margin和padding的用法与区别--以及bug处理方式
  14. Web设计中打开新页面或页面跳转的方法
  15. dojo小代码
  16. 【HTML打印】HTML直接调用window下的打印机并执行打印任务(简单打印任务生成)
  17. airflow 实战
  18. iconfont 入门级使用方法
  19. [JSOI2016]扭动的回文串
  20. QT源码解析(七)Qt创建窗体的过程,作者“ tingsking18 ”(真正的创建QPushButton是在show()方法中,show()方法又调用了setVisible方法)

热门文章

  1. Spring velocity 中文乱码 解决方案
  2. mosquitto $SYS下topic
  3. 详解 boost 库智能指针(scoped_ptr&lt;T&gt; 、shared_ptr&lt;T&gt; 、weak_ptr&lt;T&gt; 源码分析)
  4. 关闭危害的端口DOS命令(转载)
  5. Android 依赖注入: Dagger 2 实例解说(一)
  6. 跑酷游戏的一些bug总结(滥用FixedUpdate的坑)
  7. linux 下面压缩,解压.rar文件以及rar,unrar实例
  8. DLL编写中extern “C”和__stdcall的作用
  9. 亿级日PV的魅族云同步的核心协议与架构实践(转)
  10. [转]Python中函数的值传递和引用传递