Java基础【包装类】

时间:2020-05-31 21:22:55   收藏:0   阅读:46

包装类

装箱

  1. Integer i=new Integer(int i) 参数为基本数据类型
  2. Integer i=new Integer(Stirng str) 参数为基本数据类型的字符串,否则会报异常,例如"a"

拆箱

  1. int i2=i.intValue()

备注:
jdk1.5之后支持自动装箱与拆箱

基本数据类型与字符串相互转换

基本数据类型转换成字符串

  1. 添加"" 例如1+""
  2. Integer.toString(int i)
  3. String.Valueof(int i)

字符串转换成基本数据类型

  1. int i=Integer.parseInt(String str) 参数为基本数据类型的字符串

原文:https://www.cnblogs.com/kwdlh/p/13021429.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!