Package

Package

基本类型与对应的包装类对象之间的转换 ==> 装箱 拆箱

基本类型的数据不是对象,只是一个单纯的数据,功能简单,只能做一些运算操作
引用类型可以创建对象,可以调用这个对象的一些方法完成一些功能

常用操作: ==> 基本类型和字符串互相转换

代码例

Integer i = new integer(4); ==> 使用构造函数 -->java5后 Integer i = 4( 装箱)

Integer iii = Integer.valueOf(4) ==>(基本-->包装) -->使用Integer中的valueOf方法

int num = i . intValue(); ==> (包装-->基本) -->使用intValue()方法 i = i + 5

String转换为对应的基本类型

除了Character类之外,其他所有包装类都具有parseXxx静态方法-->字符串转对应基本类型

Integer类

1.Integer类在对象中包装了一个基本int型
2.该类提供多个方法,能在int和string互相转换
3.提供一些常量和方法

构造方法

public Integer(int value)
public Integer(String s)

2.基本类型转字符串
(int --> Integer)
1.和""拼接
2.public static String valueOf(int i)
String.valueOf();
3.int -- integer -- String(Integer.toString方法)
Integer.valueOf().toString();
4.public static String toString(int i)(Integer中静态方法)

3.字符串转基本类型
(Integer --> int)
1.String -- Integer -- int

2.public static int parseInt(String str)

基本数据类型包装类, 其中7种都有parseXXX方法,character中没有该方法
--(转换的字符串必须规格符合)--
BigInteger

1.可以让超过Integer范围内的数据进行运算
2.构造方法
public BigInteger(String str)
3.方法
public BigInteger add(BigInteger val) ==> +
public BigInteger substract(BigInteger val) ==> -
public BigInteger multiply(BigInteger val) ==> *
public BigInteger divide(BigInteger val) ==> /
public BigInteger divideAndRemainder(BigInteger val) ==>取除数和余数

BigDecimal

1.不可变,任意精度...精确计算浮点数
2.public BigDecimal(字符串)
3.方法
public BigDecimal add(BigDecimal augund)
开发推荐==>传入字符串使用BigDecimal或者valueOf()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值