包装类中Integer类最全详解
目录
概述
字段
构造方法
方法
bitCount(int i)
byteValue()
compare(int x, int y)
compareTo(Integer anotherInteger)
compareUnsigned(int x, int y)
decode(String nm)
divideUnsigned(int dividend, int divisor)
getInteger(String nm)
getInteger(String nm, int val)
highestOneBit(int i)
lowestOneBit(int i)
max(int a, int b)
min(int a, int b)
reverse(int i)
reverseBytes(int i)
signum(int i)
sum(int a, int b)
parse方法
parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
parseInt(String s)
parseInt(String s, int radix)
Value方法
byteValue()
shortValue()
doubleValue()
floatValue()
intValue()
longValue()
ValueOf方法
valueOf(int i)
valueOf(String s)
valueOf(String s, int radix)
概述
Integer类继承了Number实现了Comparable Integer类存在java.lang包下,使用时不需要导包
public final class Integer extends Number implements Comparable
Integer类在对象中包装基本类型int的值。 Integer类型的对象包含单个字段,其类型为int 。
字段
public static final int BYTES = SIZE / Byte.SIZE;
public static final int MIN_VALUE = 0x80000000;
public static final int MAX_VALUE = 0x7fffffff;
public static final int SIZE = 32;
public static final Class
构造方法
int x1 = new Integer(2);//x1=2
int y1 = new Integer("5");//y1=5
Integer x2 = 5;
Integer y2 = 10;
Integer x3 = new Integer(20);
Integer y3 = new Integer(30);
方法
bitCount(int i)
返回指定的 int值的二进制补码表示形式中的 int 。
public static int bitCount(int i) {
// HD, Figure 5-2
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
}
byteValue()
返回此值 Integer为 byte的基本收缩转换后。
public byte byteValue() {
return (byte)value;
}
compare(int x, int y)
以数字方式比较两个 int值。 返回值是1或-1或 0
1表示传入的参数前面比后面大 -1表示传入的参数后面比前面大 0表示传入的参数两者相等
public static int compare(int x, int y) {
return (x < y) ? -1