1、基本数据类型不具备对象的特性,为了让基本数据类型也具备对象的特征,java提供了包装类
2、基本类型和包装类之间的对应关系
基本类型 对应的包装类
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
3、包装类主要提供了2大方法:
a、将本类型和其他基本类型进行转换的方法
b、将字符串和本类型及包装类互相转换的方法
4、Integer包装类的构造方法:
a、创建一个Integer对象,表示指定的int值
Integer(int value)
b、创建一个Integer对象,表示String参数所指示的int值
eg:
int i = 2;
Integer m = new Integer(5); //定义Integer包装类对象,值为5
Integer n = new Integer(“8”);//定义Integer包装类对象,值为8
5、Integer包装类的常用方法:
返回值 方法名 解释
byte byteValue() 转换为byte类型
double doubleValue() 转换为double类型
float floatValue() 转换为float类型
int intValue() 转换为int类型
long longValue() 转换为long类型
static int parseInt(String s) 将字符串转换为int类型
String toString() 转换为字符串类型
static Integer valueOf(String s) 将字符串转换为Integer类型
eg:
Integer score =new Integer(10); //创建Integer包装类对象
double score2=score.doubleValue(); //转换为double类型
float socre3=score.floatValue(); //转换为 float类型