ArrayList:
* 底层数据结构是数组,增删慢
LinkedList:
* 底层数据结构是链表,增删快
* 线程不安全,效率高
package java.thread;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
*/
public class ListDemo {
public static void main(String[] args) {
//ArrayList
List<String> list1 = new ArrayList<String>();
long start = System.currentTimeMillis() ;
for (int i = 0 ; i < 1000000 ; i ++) {
list1.add(0,"tom" + i);
}
System.out.println(System.currentTimeMillis() - start);
//linkedList
list1 = new LinkedList<String>();
start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
list1.add(0, "tom" + i);
}
System.out.println(System.currentTimeMillis() - start);
}
}