关于ArrayList与LinkedList的add时间比较
Tonight, I conducted a small experiment to compare the time it takes to add the same data using different data structures.
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
List<Cat> l = new ArrayList<>();
long start = System.currentTimeMillis();
System.out.println("开始时间:" + start);
for (long i = 0; i < 5990000; i++) {
l.add(new Cat(i));
}
long end = System.currentTimeMillis();
System.out.println("结束时间:" + end);
System.out.println("总用时间:" + (end - start));
}
I've heard that the former insertion is slower, but through this small example, I didn't see the former being slower than the latter. Instead, the former was faster by quite a bit. Can anyone provide guidance?