我们经常为用到integer.valueof(string str)这个方法,如果字符串格式不对,这个方法会抛出一个系统异常numberformatexception
在integer类中的定义如下: 【程序编程相关:国内互联网创业者集体套现(转载)】这里我们就要分析一下这个方法,其中byte,short也是调用了ingeter中的方法. 【推荐阅读:一个比较有趣的自动生成迷宫程序.】 { 【扩展信息:Internet Explorer编程简】public static integer valueof(string s) throws numberformatexception return new integer(parseint(s, 10)); }这里因为parseint方法返回的int型的,这里调用了一个构造函数产生了一个新的integer实例.这里关心的是parseint方法,该方法代码如下: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"); }... 下一页