包装类的介绍

一,概述

Java提供两个类,基本类型和引用类型

1):基本类型的包装类,包装以后,具有属性和方法。

基本类型对应包装类
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
charCharacter
booleanBoolean

 2):装箱与拆箱

装箱 指基本数据类型转换到包装类;

拆箱 指包装类转换到基本数据类型。

int a1=5;

//装箱

Integer a2=new Integer(a1); 

Integer a3=Integer.ValueOf(a1);

 //拆箱

int a4=a2.intValue();

 2.1):自动装箱与拆箱

//自动装箱

Integer a5=a1;

//自动拆箱

int a6=a2;

 2.2):基本类型和字符串之间的转换

1,基本数据类型可以自动转换为字符串;

2,字符串需要手动进行转换为基本数据类型;

 3):主要构造方法

Integer(int value)
          构造一个新分配的 Integer 对象,它表示指定的 int 值。
Integer(String s)
          构造一个新分配的 Integer 对象,它表示 String 参数所指示的 int 值。

 4):常用方法

 bytebyteValue()
          以 byte 类型返回该 Integer 的值。
 doubledoubleValue()
          以 double 类型返回该 Integer 的值。
 floatfloatValue()
          以 float 类型返回该 Integer 的值。
 intintValue()
          以 int 类型返回该 Integer 的值。
 longlongValue()
          以 long 类型返回该 Integer 的值。
static intparseInt(String s)
          将字符串参数作为有符号的十进制整数进行解析。
 shortshortValue()
          以 short 类型返回该 Integer 的值。
 StringtoString()
          返回一个表示该 Integer 值的 String 对象。
static IntegervalueOf(int i)
          返回一个表示指定的 int 值的 Integer 实例。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值