图解:
源码:
public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, java.io.Serializable
1 RandomAccess:随机访问
1 public static void main(String[] args) { 2 ArrayList<String> list = new ArrayList(); 3 for (int i = 0; i < 100000; i++) { 4 list.add("odd Point" + i); 5 } 6 //随机访问 7 long start = System.currentTimeMillis(); 8 for (int i = 0; i < list.size(); i++) { 9 list.get(i); 10 } 11 long end = System.currentTimeMillis(); 12 System.out.println("随机访问时间:"+(end-start)); 13 14 //顺序访问 15 start = System.currentTimeMillis(); 16 Iterator<String> iterator = list.iterator(); 17 while(iterator.hasNext()){ 18 iterator.next(); 19 } 20 end = System.currentTimeMillis(); 21 System.out.println("顺序访问时间:"+(end-start)); 22 }
2 Cloneable:可克隆
3 Serializable:可序列化