包装类

基本数据类型 包装类型
int Integer
short Short
double Double
boolean Boolean
long Long
char Character
byte Byte
float Float

装箱:
基本类型转换为包装类型
拆箱:
包装类型(对象类型)转换为基本类型

成员方法
static 基本类型 parseXXX(需要改变的字符串或者字符串名)
例如:
装箱
int a=20
Integer i=new Integer(a);
拆箱
int b=i.intValue();
System.out.println(i);
System.out.println(b);
在JDK5以上可以自动装箱拆箱:
自动装箱代码怎么写
Integer ii=50;

	自动拆箱
	int it=ii;
	System.out.println(ii);
	System.out.println(it);

//需求:把字符串类型的10转换为int类型的10
String s="10";
Integer num=Integer.parseInt(s);
System.out.println("num+100="+(num+100));//这一行是为了测试是不是转换成功了,如果转换成功就会输出num+100=110
注意!!!!
除了Character类以外,其他的其中包装类都有parseXXX方法
如果字符串像转换成cha类型的数据,可以通过:String类中的方法toChararry(),charAt()。

原文地址:https://www.cnblogs.com/yangzhenghua/p/13965600.html