Integer包装类 API文档深入研究---1.0

今天我们来深入研究一下Integer的包装类


需求1:将100这个数据,计算出它的二进制,八进制,十六进制

需求2:如何用代码求出int类型的数据范围

  为了对基本数据类型进行跟多的操作,更方便的操作,Java就针对每一个基本数据类型都提供了对应的类类型,我们叫做包装类类型。 

包装类类型:

byte                 Byte

short               Short

int                    Integer

long                 Long

float                 Float

double             Double

char                 Character

boolean           Boolean     

包装类常见的使用场景:

1、集合中的泛型

2、用于基本数据类型与字符串之间做转换使用 


public static String toBinaryString(int i) 

查看API文档我们知道:

public static String toBinaryString(int i)

在基数2中返回整数参数的字符串表示形式为无符号整数。

如果参数为负,则无符号整数值为参数加2 32 ; 否则就等于论证。 该值转换为二进制(基数2)的ASCII数字字符串,没有额外的前导0 s。

可以通过调用Integer.parseUnsignedInt(s, 2)从返回的字符串s中恢复参数的值。

如果无符号幅度为零,则由单个零字符'0''\u0030' )表示; 否则,无符号大小的表示的第一个字符将不是零字符。 字符'0''\u0030' )和'1''\u0031' )用作二进制数字。

参数

i - 要转换为字符串的整数。

结果

由二进制(基数2)中的参数表示的无符号整数值的字符串表示形式。

参考代码:

public class test {
    public static void main(String[] args) {
        //public static String toBinaryString(int i) 求int类型数据的二进制
        String s = Integer.toBinaryString(100);
        System.out.println("100的二进制为:" + s);
    }
}
100的二进制为:1100100

Process finished with exit code 0

 例如求int类型的八进制、int类型的十六进制举一反三即可(通过查看API文档)

参考代码:

public class test {
    public static void main(String[] args) {
        //public static String toBinaryString(int i) 求int类型数据的二进制
        String s = Integer.toBinaryString(100);
        System.out.println("100的二进制为:" + s);

        //public static String toOctalString(int i) 求出int类型数据的八进制
        String s1 = Integer.toOctalString(100);
        System.out.println("100的八进制为:" + s1);

        //public static String toHexString(int i) 求出int类型数据的十六进制
        String s2 = Integer.toHexString(100);
        System.out.println("100的十六进制为:" + s2);
    }
}

100的二进制为:1100100
100的八进制为:144
100的十六进制为:64

Process finished with exit code 0


 public static final int MIN_VALUE

查看API文档我们知道:

 public static int min(int a, int b)

返回两个 int的较小值,就像调用 Math.min一样

参数

a - 第一个操作数

b - 第二个操作数

结果

较小的 ab

参考代码:

public class test {
    public static void main(String[] args) {
        //求出int类型数据的最小值
        //public static final int MIN_VALUE
        System.out.println("int类型数据的最小值为:" + Integer.MIN_VALUE);

    }
}

int类型数据的最小值为:-2147483648

Process finished with exit code 0


 public static final int MAX_VALUE

查看API文档我们知道:

public static int max(int a,
                      int b)

返回两个 int的较大值,就像调用 Math.max一样

参数

a - 第一个操作数

b - 第二个操作数

结果

ab的较大 b

参考代码:

public class test {
    public static void main(String[] args) {
        
        //求出int类型数据的最大值
        //public static final int MAX_VALUE
        System.out.println("int类型数据的最大值为:" + Integer.MAX_VALUE);

    }
}

int类型数据的最大值为:2147483647

Process finished with exit code 0

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liangzai2048

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值