public final class Integer extends Number implements Comparable
Integer 类是一个final类,继承Number,实现了Comparable接口
最小值
@Native public static final int MIN_VALUE = 0x80000000;
最大值
@Native public static final int MAX_VALUE = 0x7fffffff;
原始类型
public static final Class TYPE = (Class) Class.getPrimitiveClass("int");
可以代表所有数字的字符串数组
final static char[] digits = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f' , 'g' , 'h' ,
'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
'o' , 'p' , 'q' , 'r' , 's' , 't' ,
'u' , 'v' , 'w' , 'x' , 'y' , 'z'
};
根据进制获取字符串形式
public static String toString(int i, int radix) {
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) //是否小于2和大于36,超出范围按10进制转换
radix = 10;
/* Use the faster version */
if (radix == 10) { //如果是10进制 则直接调用tostring
return toString(i);
}
char buf\[\] = new char\[33\]; //10个数字+26个字母
boolean negative = (i < 0); //负数标记
int charPos = 32;
if (!negative) {
i = -i; //正数转负数
}
while (i <= -radix) { //根据进制计算每一位的字符
buf\[charPos--\] = digits\[-(i % radix)\];
i = i / radix;
}
buf[charPos] = digits[-i]; //值的最高位
if (negative) {
buf[--charPos] = '-'; //如果是负数增加个符号
}
return new String(buf, charPos, (33 \- charPos));
}
判断位数的方式也很棒
final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE };