什么是Integer.parseInt()源码
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,这篇文章将为大家详细讲解有关什么是Integer.parseInt()源码,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。character.digit
千家信息网最后更新 2025年12月02日什么是Integer.parseInt()源码
这篇文章将为大家详细讲解有关什么是Integer.parseInt()源码,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
character.digit(char ch, int radix) 将radix进制的ch转化成十进制数;
character.digit(int codePoint, int radix) 将radix进制的askll码对应的char转化成十进制数。
例:String s=2147483648
result初始值为0,
limit= -Integer.MAX_VALUE,即 -2147483647,
上一个result和limit比较,排除21474836471这种越界的情况
result*10和limit+当前位比较,排除2147483648这种越界的情况(-2147483640<-2147483647+8)
result-=当前位
public static int parseInt(String s) throws NumberFormatException { return parseInt(s,10); } public static int parseInt(String s, int radix) throws NumberFormatException { 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); 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; }关于什么是Integer.parseInt()源码就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
源码
内容
十进制
情况
文章
更多
知识
篇文章
进制
十进
不错
大小
质量
长度
参考
帮助
有关
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
老城区软件开发定制
中国互联网文化科技创意园
魔兽世界服务器架设
网络安全法保护机制
传奇论坛是国内服务器吗
徐州营销网络技术怎么样
类似趣取钱软件开发
网络安全员考试模拟题
小牛互联网科技有限公司地址
软件开发行业为何分销售和售前
字典表示几维数据库
数据库加密技术的优缺点
国科大网络安全评级
服务器IP暴露马方面不安全
苹果怎么联系软件开发商
计算机网络技术博主
网络安全微信公众号标题
网络安全检查风险评估报告
单一来源智慧校园软件开发
河南互联网科技企业名单
ess无法启动数据库
数据库加密技术的优点
网络安全法法案亮点
服务器刷单
数据库进行安全防护
计算机网络技术英语考几级
软件开发招标采购需求书
服务器excel有什么用
软件开发流程心得
慈溪现代化刀片服务器售后服务