Java包装类 - Integer包装类

Integer 包装类Integer类中包装的是int的值.Integer 包装类 的父类和实现了那些接口?Integer 包装类 是继承了 number抽象类 且实现了 Comparable 接口.number类 实现了 java.io.Serializable接口.Integer 都有那些方法?bitCount方法 静态方法这个方法可以用来统计某个int值转成二进制后中1的数量.// 例如:public static void main(String[] args) {
摘要由CSDN通过智能技术生成

Integer 包装类

Integer类中包装的是int的值.

Integer 包装类 的父类和实现了那些接口?

  1. Integer 包装类 是继承了 number抽象类 且实现了 Comparable 接口.
  2. number类 实现了 java.io.Serializable接口.

Integer 都有那些方法?

  1. 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	
    */
    
  2. btyeValue 方法 实例方法
    将Integer 中的数值收缩为byte类型,未发现其他作用.
  3. compare 方法 静态方法
    compare(int x, int y) , x 与 y 进行比较
    如果 x > y 返回 1
    如果 x < y 返回 -1
    如果 x = y 返回 0
  4. compareTo(Integer x) 实例方法
    // 示例演示:
    public static void main(String[] args) {
         
        Integer i = 10;
        int i1 = i.compareTo(5);
        System.out.println
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值