类型转换

来源:互联网 发布:快阅读软件 编辑:程序博客网 时间:2024/05/23 13:06

int<->Integer

Integer in1=new Integer(10);

Integer in2=Integer.valueOf(20);

int n=in2.intValue();

Integer in3=10; 自动装箱

int n2=in2; 自动拆箱

int型保存在栈内存,参数传递时直接传递值;Integer型保存在堆内存中,参数传递时传递的是对象的引用。

BigDecimal类用于精确计算

BigDecimal b1=new BigDecimal(Double.toString(23.00));
BigDecimal b2=BigDecimal.valueOf(12.12);

double d=b1.doubleValue();

int n=b2.intValue();

BigInteger可以准确地表示任何大小的整数值

boolean有两个值:false和true,值使用前需要被初始化

Boolean有三个值:false,true,null


0 0
原创粉丝点击