java基础-基础类型包装类型

想要对基本类型数据进行更多的操作,最方便的方式就是将其封装成对象。
为啥呢?因为在对象描述中就可以定义更多的属性和行为对该基本数据类型进行操作。
【八种基本数据类型的包装类】
byte ——Byte
short ——Short
int ——Integer
long-----Long
float-----Float
double----Double
char----Character
boolean---Boolean 基本数据类型变成对象包装类的好处】
1 可以将基本数据和字符串之间进行互相的转换。
public static void main(String[] args) { Integer index = 12;//基础类型包装类型Integer
String str_index = index.toString();//包装类型Integer转换为字符串
index = Integer.parseInt(str_index);//字符串转为包装类型Integer }
2 包含每种基本数据类型的相关属性如最大值、最小值等,以及相关的操作方法。
public static void main(String[] args) { Integer max = Integer.MAX_VALUE;//int最大值
Integer min = Integer.MIN_VALUE;//int最小值
}
3 基本类型与包装类型*转换.也可以称为自动拆箱与自动装箱
public static void main(String[] args) { Integer index = 100;
int _index = index;//自动拆箱
index = _index;//自动装箱 }
上一篇:C++拷贝构造函数的调用时机


下一篇:数位DP按位枚举模板