public class ListPerformanceTest { public static void addTest(List list) { System.out.println(list.getClass().getName() + "开始测试"); long startTime = System.currentTimeMillis(); for (int i = 0; i <10000000; i++) { list.add("test" + i); } long endTime = System.currentTimeMillis(); System.out.println("耗时: " + (endTime - startTime) + " ms"); }
public static void main(String[] args) { List arrayList = new ArrayList<>(); List linkedList = new LinkedList<>(); addTest(arrayList); addTest(linkedList); } } ```