包装类基本知识

包装类基本知识
在这八个类名中,除了Integer和Character类以外,其他六个类的类名和基本数据类型一致,只是类名的第一个字面大写而已。
在这八个类中,除了Character和Boolean以外,其他的都是“数字型”,“数字型”都是java.lang.Number的子类。Number类是抽象类,因此它的抽象方法,所有子类都需要实现。Number类提供了抽象方法:intValue()、longValue()、floatValue()、doubleValue(),意味着所有的“数字型”包装类都可以相互转型。
包装类基本知识
包装类基本知识
包装类基本知识
public class TestWrappedClass{
public static void main(String[ ] args){
//基本数据类型转成包装类对象
Integer a = new Integer(2);
Integer b = Integer.ValueOf(30);
//把包装类对象转成基本数据类型
int c = b.intValue();
double d = b.doubleValue();
//把字符串转成包装类对象
Integer e = new Integer(“9999”);
Integer f = Integer.parseInt(“999000”);
//把包装类对象转成字符串
String str = f.toString();//""+f
//常见的常量
System.out.println(“int类型最大的整数:”+Integer.MAX_VALUE);
}
}