int的最值可以通过其对应的封装类Integer.MAX_VALUE获取
package com.ly.chaizhuangxiang;
public class Int {
public static void main(String[] args) {
System.out.println("INT的最大值"+Integer.MAX_VALUE);
System.out.println("INT的最小值"+Integer.MIN_VALUE);
}
}

练习拆装箱
- 对byte,short,float,double进行自动拆箱和自动装箱
byte
装箱
public static void main(String[] args) {
byte i=1;
//基本数据类型转换为封装类
Byte by=new Byte(i);
System.out.println(by);
}
拆箱
byte i=3;
Byte by=new Byte(i);
//封装类转换为基本类型,该种方式不会触发自动装箱
byte i1=by.byteValue();
//自动转换就叫拆箱
int i2=by;
System.out.println(i2);
short
装箱
public static void main(String[] args) {
short i=2;
//基本数据类型转换为封装类
Short sh=new Short(i);
System.out.println(sh);
}
装箱
short i=5;
Short sh=new Short(i);
//封装类转换为基本类型
short i1=sh.shortValue();
//自动转换就叫拆箱
short i2=sh;
System.out.println(i2);
Double
public static void main(String[] args) {
double d1=20.0;
Double d2=null;
d2=d1;//自动装箱
d1=d2;//自动拆箱
System.out.println("自动装箱"+d2);
System.out.println("自动拆箱"+d1);
}
拆箱有两种写法,第一种就会调用XXXValue()方法,但不会自动拆箱。
剩下的以此类比。
-
byte和Integer之间能否进行自动拆箱和自动装箱
不能. -
通过Byte获取byte的最值
public static void main(String[] args) {
System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
}

博客主要围绕基本数据类型的自动拆装箱展开练习。介绍了通过Integer.MAX_VALUE获取int最值,对byte、short、float、double进行自动拆箱和装箱操作,还提及Double拆箱的写法,指出byte和Integer间不能自动拆箱和装箱,以及通过Byte获取byte最值。
1324

被折叠的 条评论
为什么被折叠?



