一、包装类
Integer int 的包装类
Boolean boolean 的包装类
Character char的包装类
Double double的包装类
Float float 的包装类
Byte byte的包装类
Short short的包装类
Long long 的包装类
包装类具有的方法doubleValue(),floatValue(),intValue(),longValue(),shortValue(),byteValue()。
包装类没有无参构造方法,所有包装类的对象都是不可变。
将基本数据类型转换成对应的包装类称为装箱(boxing),相反的转换为开箱(unboxing)。
Integer
构造方法有
Integer(int value)
Integer(String value)
普通方法
doubleValue() 返回double类型
floatValue() 返回float类型
intValue() 返回int类型
longValue() 返回long类型
shortValue() 返回short类型
byteValue() 返回byte类型
compareTo(Integer o) 返回int类型 //比较对象的大小
tostring() 返回int类型
valueOf(String s) 返回Integer类型 //将字符串转成Integer对象
valueOf(String s,int radix) 返回Integer类型
parseInt(String s) 返回int类型 //将字符串转成int类型变量
parseInt(String s,int radix) 返回int类型
二、BigInteger与BigDecimal
BigInteger与BigDecimal都是不可变类
BigInteger与BigDecimal有实例方法add、subtract、multiple、divide、remaider、compareTo。
BigDecimal
BigDecimal的构造方法
BigDecimal(String s)
BigDecimal实例方法
add(BigDecimal d) 返回BigDecimal类型 //求和
subtract(BigDecimal d) 返回BigDecimal类型 //求差
multiple(BigDecimal d) 返回BigDecimal类型 //求积
divide(BigDecimal d) 返回BigDecimal类型返回BigDecimal类型 //求商,除不尽抛异常
divide(BigDecimal d,int scale,int roundingMode) 返回BigDecimal类型
//scale指小数点后面保留的位数, roundingMode是舍入方式BigDecimal.Round_UP与BigDecimal.Round_Down
remaider(BigDecimal d) 返回BigDecimal类型 //求余数
compareTo(BigDecimal d) 返回int类型