包装类中Integer类最全详解


概述

Integer类继承了Number实现了Comparable
Integer类存在java.lang包下,使用时不需要导包

public final class Integer extends Number implements Comparable<Integer>

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<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");

在这里插入图片描述


构造方法

在这里插入图片描述

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 : ((x ==<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值