装箱
Integer i = 10;
拆箱
int n = i; //拆箱
装箱就是 自动将基本数据类型转换为包装类型;拆箱就是 自动将包装类型转换为基本数据类型。
装箱和拆箱是如何实现的在装箱的时候自动调用的是Integer的valueOf(int)方法。而在拆箱的时候自动调用的是Integer的intValue方法。
2.代码输出结果public class Main {
public static void main(String[] args) {
Integer i1 = 100;
Integer i2 = 100;
Integer i3 = 200;
Integer i4 = 200;
System.out.println(i1==i2);
System.out.println(i3==i4);
}
}
输出结果为:true false
在通过valueOf方法创建Integer对象的时候,如果数值在[-128,127]之间,便返回指向IntegerCache.cache中已经存在的对象的引用;否则创建一个新的Integer对象。
3.Java类中不同代码块的执行顺序 4.栈(stack)、堆(heap)和方法区String str = new String("hello");
变量str放在栈上,用new创建出来的字符串对象放在堆上,而"hello"这个字面量是放在方法区的。



