object 对象不能直接强制转换为 Integer
object对象可以直接强制转换为String
Integer a = Integer.parseInt(String str)
装箱和拆箱?拆箱是自动的?
八种基本类型不是对系那个,不能作为对象调用其toString()、hashCode()、getClass()、equals()等方法
对八种基本类型,气功了针对每个基本类型的包装类
int ----Integer
char ---Character
float ----Float
double---Double
byte----Byte
short----Short
long---Long
boolean ---Boolean
box 就是基本类型用它们相对应的基本类型包起来,使得他们具有对象的特质。
unbox的方向相反,将引用类型的对象简化为值类型。
在jdk1.5之前,需要手动box and unbox
jdk1.5之后,自动完成。
wrapper 包装类中都有一个重要的静态方法parse,可以将String字符串类型转为相应的基本数据类型,如果字符串中的值不能转换为基本数据类型,则会抛出java.lang.NumberFormatException
public class parseInt {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int p = 1;
Integer q = new Integer(p);//手动装箱
int m = q.intValue();//手动拆箱
System.out.println("manual box q="+q);
System.out.println("manual unbox m="+m);
int j = 2;
Integer a = j;
int b = a;
System.out.println("auto box a="+a);
System.out.println("auto unbox b="+b);
String str = new String("30i");
try
{
int pp = Integer.parseInt(str);
System.out.println(pp);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}