当前位置:网站首页>Integer learning

Integer learning

2022-07-07 14:54:00 nsnsttn

/** * @author zzy * @createDate: 2021-11-29 10:24:15 * @description:  The source code is relatively simple , Click inside by yourself  */
public class Integer Study  {
    
    public static void main(String[] args) {
    
        // One : Four kinds of creation  Integer Methods , The first three values are  -128 ~ 127  Cache this value between 
        //1.String turn int,  Then it is automatically boxed, so there is a cache , The second parameter is base , The default is 10 Base number 
        Integer i1 = Integer.parseInt("127");
        //2.String、int turn Integer, With cache , The second parameter is base , The default is 10 Base number 
        Integer i2 = Integer.valueOf(127);
        //3. Automatic boxing , Automatically call  valueOf()
        Integer i3 = 127;
        //4. Create new objects , No cache 
        Integer i4 = new Integer(127);
        Integer i5 = 127;
        System.out.println(i1 == i5);//true
        System.out.println(i2 == i5);//true
        System.out.println(i3 == i5);//true
        System.out.println(i4 == i5);//false
        // Two :  Hexadecimal conversion 
        // 10 turn 2
        String t2 = Integer.toBinaryString(11);
        // 10 turn 8
        String t8 = Integer.toOctalString(20);
        // 10 turn 16
        String t16 = Integer.toHexString(20);
        System.out.println(t2);
        System.out.println(t8);
        System.out.println(t16);
    }
}
原网站

版权声明
本文为[nsnsttn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130613364368.html