温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java 包装成类对象

发布时间:2020-10-04 20:30:59 来源:网络 阅读:161 作者:wx5d21d5e6e5ab1 栏目:编程语言

int --Integer(类)
char--Character
double--Double
float=Float
其他的类似

创建Integer类:
Integer a=new Integer(3);
Integer b=Integer.valueOf(3);

把包装类对象转换成基本数据类型:
int c=b;
int c=b.intValue();
double d=b.doubleValue();

把字符串对象转换成包装对象:
int c=new Integer("1234")
int c=Integer.parseInt("1234")

包装对象转换成字符串:
String s=c.toString();
String s=""+c; (空格)

Integer缓存范围[-128,127]
在整个区间内,不同对象如果赋相同值,则对象一样,超过区间则不一样
缓存就是数组,该数组包含了-128到127之间的对象,如果创建的对象没超过则从数组内取,如果超过了就new一个,所以对象会不同
例子:
Integer a=123;
Integer b=123;
System.out.println(a==b);
System.out.println(a.equals(b));
true
true

Integer a=1234;
Integer b=1234;
System.out.println(a==b);
System.out.println(a.equals(b));
false
true

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI