java中的包装类

1、基本数据类型不具备对象的特性,为了让基本数据类型也具备对象的特征,java提供了包装类

2、基本类型和包装类之间的对应关系

       基本类型    对应的包装类

          byte             Byte

          short           Short

          int                Integer

          long            Long

          float            Float

          double       Double

          char           Character

          boolean    Boolean

3、包装类主要提供了2大方法:

      a、将本类型和其他基本类型进行转换的方法

      b、将字符串和本类型及包装类互相转换的方法

4、Integer包装类的构造方法:

      a、创建一个Integer对象,表示指定的int值

             Integer(int value)

      b、创建一个Integer对象,表示String参数所指示的int值

   eg:

          int i = 2;

          Integer m = new Integer(5); //定义Integer包装类对象,值为5

          Integer n  = new Integer(“8”);//定义Integer包装类对象,值为8

5、Integer包装类的常用方法:

    返回值                    方法名                                  解释

    byte                         byteValue()                     转换为byte类型

    double                    doubleValue()               转换为double类型

    float                         floatValue()                    转换为float类型

    int                             intValue()                       转换为int类型

    long                         longValue()                   转换为long类型

    static int                  parseInt(String  s)       将字符串转换为int类型

    String                      toString()                       转换为字符串类型

    static Integer         valueOf(String s)          将字符串转换为Integer类型

eg:

         Integer score =new Integer(10);     //创建Integer包装类对象

         double score2=score.doubleValue();  //转换为double类型

         float  socre3=score.floatValue();   //转换为 float类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值