Java基础【包装类】
时间:2020-05-31 21:22:55
收藏:0
阅读:46
包装类
装箱
- Integer i=new Integer(int i) 参数为基本数据类型
- Integer i=new Integer(Stirng str) 参数为基本数据类型的字符串,否则会报异常,例如"a"
拆箱
- int i2=i.intValue()
备注:
jdk1.5之后支持自动装箱与拆箱
基本数据类型与字符串相互转换
基本数据类型转换成字符串
- 添加"" 例如1+""
- Integer.toString(int i)
- String.Valueof(int i)
字符串转换成基本数据类型
- int i=Integer.parseInt(String str) 参数为基本数据类型的字符串
原文:https://www.cnblogs.com/kwdlh/p/13021429.html
评论(0)