Integer 包装类
Integer类中包装的是int的值.
Integer 包装类 的父类和实现了那些接口?
- Integer 包装类 是继承了 number抽象类 且实现了 Comparable 接口.
- number类 实现了 java.io.Serializable接口.
Integer 都有那些方法?
- bitCount方法 静态方法
这个方法可以用来统计某个int值转成二进制后中1的数量.// 例如: public static void main(String[] args) { for (int i = 1; i < 16; i++) { System.out.println(i +"==>" +Integer.bitCount(i)); } } /* int 二进制 bitCount方法结果 1 ⇒ 1 ⇒ 1 2 ⇒ 10 ⇒ 1 3 ⇒ 11 ⇒ 2 4 ⇒ 100 ⇒ 1 5 ⇒ 101 ⇒ 2 6 ⇒ 110 ⇒ 2 7 ⇒ 111 ⇒ 3 8 ⇒ 1000 ⇒ 1 9 ⇒ 1001 ⇒ 2 10 ⇒ 1010 ⇒ 2 11 ⇒ 1011 ⇒ 3 12 ⇒ 1100 ⇒ 2 13 ⇒ 1101 ⇒ 3 14 ⇒ 1110 ⇒ 3 15 ⇒ 1111 ⇒ 4 */
- btyeValue 方法 实例方法
将Integer 中的数值收缩为byte类型,未发现其他作用. - compare 方法 静态方法
compare(int x, int y) , x 与 y 进行比较
如果 x > y 返回 1
如果 x < y 返回 -1
如果 x = y 返回 0 - compareTo(Integer x) 实例方法
// 示例演示: public static void main(String[] args) { Integer i = 10; int i1 = i.compareTo(5); System.out.println