包装类型
约 279 字小于 1 分钟
2026-04-04
包装类型
将普通类型数据转换为对象类型数据
包装类(包装器类型) :
byte -> Byte
short -> Short
int -> Integer
long -> Long
float -> Float
double -> Double
char -> Character
boolean -> Boolean创建对象
//创建对象
Integer i = new Integer(1);
Integer num = 5;自动装箱
基本类型 -> 包装器类型
// 1.创建对象
Character ch = new Character('a');
// 2.直接赋值
Double d =5.6;自动拆箱
包装器类型 -> 基本类型**public int intValue()**
Integer n= 58;
int f= n.intValue();
System.out.println(f);字符串 转换为 包装类
public static Integer valueOf(String s)public static Integer valueOf(int i) 使用时注意数据格式
Integer str=Integer.valueOf("5");
System.out.println(str);基本类型与字符串类型的转换
基本类型 --> String类型
1. 基本类型的值 + ""
2. 包装类的toString()方法
public static String toString(int i):直接将基本类型转换为String类型
------------------------
Integer.toString(34)
------------------------
3. 使用String类中的valueOf()方法
public static String valueOf(基本类型 名称)
------------------------
String.valueOf(10);
------------------------String类型 --> 基本类型
1. 使用包装类的parseXXX("字符串")
public static int parseInt(String s)
------------------------------
Integer.parseInt("2344");
------------------------------贡献者
更新日志
2026/4/5 03:39
查看所有更新日志
fb8bc-更新为vuepress于