ArrayListTest.java
package qqq;
import java.util.ArrayList;
public class ArrayListTest {
/**
* @param args
*/
public static void main(String[] args) {
long startTimeAL1;
long endTimeAL1;
long startTimeAL2;
long endTimeAL2;
//AL顺序添加500000
startTimeAL1 = System.currentTimeMillis();
ArrayList aL = new ArrayList();
for(int i=0;i<50000; i++){
aL.add("000");
}
endTimeAL1 = System.currentTimeMillis();
//AL前段添加
startTimeAL2 = System.currentTimeMillis();
ArrayList aL2 = new ArrayList();
for(int i=0;i<50000; i++){
aL.add(1,"000");
}
endTimeAL2 = System.currentTimeMillis();
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL1-startTimeAL1)+"ms");
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL2-startTimeAL2)+"ms");
}
}
//********************************************************************************
HashMapTest.java
package qqq;
import java.util.HashMap;
public class HashMapTest {
/**
* @param args
*/
public static void main(String[] args) {
long startTimeAL1;
long endTimeAL1;
long startTimeAL2;
long endTimeAL2;
//AL顺序添加500000
startTimeAL1 = System.currentTimeMillis();
HashMap hM1 = new HashMap();
for(int i=0;i<50000; i++){
hM1.put(i,"000");
}
endTimeAL1 = System.currentTimeMillis();
//AL前段添加
startTimeAL2 = System.currentTimeMillis();
HashMap hM2 = new HashMap();
for(int i=0;i<50000; i++){
hM2.put(50000-i, "000");
}
endTimeAL2 = System.currentTimeMillis();
//System.out.println(hM1.size());
//System.out.println(hM2.size());
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL1-startTimeAL1)+"ms");
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL2-startTimeAL2)+"ms");
}
}
//********************************************************************************
LinkedListTest.java
package qqq;
import java.util.ArrayList;
public class LinkedListTest {
/**
* @param args
*/
public static void main(String[] args) {
long startTimeAL1;
long endTimeAL1;
long startTimeAL2;
long endTimeAL2;
//AL顺序添加500000
startTimeAL1 = System.currentTimeMillis();
ArrayList aL = new ArrayList();
for(int i=0;i<50000; i++){
aL.add("000");
}
endTimeAL1 = System.currentTimeMillis();
//AL前段添加
startTimeAL2 = System.currentTimeMillis();
ArrayList aL2 = new ArrayList();
for(int i=0;i<50000; i++){
aL.add(1,"000");
}
endTimeAL2 = System.currentTimeMillis();
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL1-startTimeAL1)+"ms");
System.out.println("顺序添加50000条数据耗时:"+(endTimeAL2-startTimeAL2)+"ms");
}
}