1. 內存模型java
1.1 對象緩存緩存
public static void main(String[] args) { Integer a = 127, b = 127, c = -128, d = -128; Integer e = 128, f = 128, g = -129, h = -129; System.out.println(a == b); // true
System.out.println(c == d); // true
System.out.println(e == f); // false
System.out.println(g == h); // false
}
JVM對基本類型(boolean, float, double除外)進行了緩存,Integer默認範圍是-128~127並可經過JVM參數修改上限,因爲Integer是final類,故緩存範圍內的Integer自動裝箱時不產生新對象。框架
2. 集合框架spa
2.1 方法 List<E> subList(int fromIndex, int toIndex)code
public static void main(String[] args) { List<Integer> arrayList = new ArrayList<Integer>(10); List<Integer> linkedList = new LinkedList<Integer>(); for (int i = 0; i < 10; i++) { arrayList.add(i); linkedList.add(i); } List<Integer> subArrayList = arrayList.subList(1, 4); List<Integer> subLinkedList = arrayList.subList(1, 4); System.out.println(subArrayList.getClass()); // class java.util.ArrayList$SubList
System.out.println(subLinkedList.getClass()); // class java.util.ArrayList$SubList
arrayList = (ArrayList<Integer>) subArrayList; // throws java.lang.ClassCastException
}
List接口聲明瞭subList方法,ArrayList與LinkedList中subList返回ArrayList中非靜態內部內SubList做爲原List的視圖,對SubList的修改會形成原List的變化。對象