Integer数据和int数据之间的区别;

来源:互联网 发布:淘宝网站策划 编辑:程序博客网 时间:2024/06/03 06:42
    // Integer类;

//********构造方法*********************
int n=3;
Integer i1=new Integer(n);
System.out.println(i1);
String s=”111”;//数字类型;
Integer i2=new Integer(s);
System.out.println(i2);

//***********自动拆箱装箱********************
//拆箱由引用数据类型转换成基本数据类型;
// Integer —>int
//Interger可以创建对象,而int不可以,只能代表数据;
//装箱由基本数据类型转换成引用数据类型;
// int——>Integer

//**************转换功能****************
//自动转换;大—-《小
short st2=3;
char c=’a’;
int n1=st2;
int n2=c;
double d=n2;
//强制转换;大—》小
short st=12;
short st1=(short)(st+3);
char c1=(char)97;
System.out.println(c1);//a
//字符串转换成int;
String s3=”333”;//数字型;将字符串参数作为有符号的十进制整数进行解析。
int n3=Integer.parseInt(s3);
System.out.println(n3);//333;

    System.out.println(Short.MAX_VALUE);    System.out.println(Short.MIN_VALUE);}

}

原创粉丝点击