List、Map、Set
- List
List部分方法的简单测试- ArrayList
- 数组自动扩容算法
- LinkedList
- Vector
- Map
- HashMap
- TreeMap
- Set
- HashSet
- TreeSet
一:List


1> ArrayList

-
ArrayList采用的扩容机制(
默认取0,add时自动取10,1.5倍扩容)

-
测试该扩容机制public class ListTest { public static void main(String[] args) { int oldCapacity = 10; System.out.println(1 >> 1); // 0 System.out.println(-1 >> 1); // -1 System.out.println(1 >> 2); // 0 System.out.println(1 >>> 1); // 0 System.out.println(-1 >>> 1); // 2147483647 System.out.println(1 >>> 2); // 0 int newCapacity = oldCapacity + (oldCapacity >> 1); System.out.println(newCapacity); // 15 int a = 12; int b = 26; int c = 33; System.out.println(a+(a>>1)); // 18 = 12+6 System.out.println(b+(b>>1)); // 39 = 26+13 System.out.println(c+(c>>1)); // 49 = 33+16 System.out.println(c*1.5); // 49.5 System.out.println(Math.round(c*1.5)); // 50:long System.out.println(Math.ceil(c*1.5)); // 50.0:double System.out.println(Math.floor(c*1.5)); // 49.0:double System.out.println(c*1.5*(-1)); // -49.5 System.out.println(Math.round(c*1.5*(-1))); // -49:long System.out.println(Math.ceil(c*1.5*(-1))); // -49.0:double System.out.println(Math.floor(c*1.5*(-1))); // -50.0:double } }
-
2> LinkedList

-
LinkedList内部的Node
-
LinkedList的add逻辑

3> Vector(对外提供的方法全部被synchronized修饰,操作是线程安全的)

-
Vector采用的扩容机制(初始化容量10,扩增容量大小可以自定义+默认2倍)

二:Map

1> HashMap

2> TreeMap

三:Set
1> HashSet

2> TreeSet






