• 包装类之代表“Integer"


    基本数据类型对象包装类

    优势:

    1:可以通过对象中的属性和行为操作基本数据。
    2:可以实现基本数据类型和字符串之间的转换。

    列表

     **基本类型 包装类**
     byte  Byte
    short  Short     paserShort(numstring);
    int  Integer   静态方法:parseInt(numstring)
    long  Long
    float  Float
    double    Double
    char  Character
    Boolean   Boolean
    
    Integer:

    和字符串之间的转换:
    数字格式的字符串转成基本数据类型的方法:
    1:将该字符串封装成了Integer对象,并调用对象的方法intValue();
    2:使用Integer.parseInt(numstring):不用建立对象,直接类名调用;

    将基本类型转成字符串:
    1:Integer中的静态方法 String toString(int);
    2:int+"";

    进制的转换:
    转成二进制:toBinaryString
    转成八进制:toOctalString
    转成十六进制:toHexString
    toString(int num,int radix);

    将其他进制转换十进制:
    parseInt(string,radix);

    写法和自动拆箱装箱:
    Integer i = new Integer(4); //1.5版本之前的写法
    Integer i = 4; //自动装箱,1.5版本后的写法;
    i = i + 5;
    //i对象是不能直接和5相加的,其实底层先将i转成int类型,在和5相加。而转成int类型的操作是隐式的。自动拆箱:拆箱的原理就是i.intValue();i+5运算完是一个int整数。如何赋值给引用类型i呢?其实有对结果进行装箱。

  • 相关阅读:
    查看python关键字
    命令终端执行python
    Codeforces-462C. A Twisty Movement
    Codeforces-462A. A Compatible Pair
    Codeforces-446C. Pride
    Codeforces-Hello 2018C. Party Lemonade(贪心)
    Codeforces-33C. Wonderful Randomized Sum
    Codeforces-118D. Caesar's Legions(lazy dynamics)
    codeforces-73C. LionAge II
    Gym 101510C-Computer Science
  • 原文地址:https://www.cnblogs.com/jwlxtf/p/7932659.html
Copyright © 2020-2023  润新知