System.out.println("arraylist time get:" + (agend - agbegin));
long lgbegin = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
llist.get(i);
}
long lgend = System.currentTimeMillis();
System.out.println("linkedlist time get:" + (lgend - lgbegin));
/*
*iterator方法遍历比较
* */
long lgibegin = System.currentTimeMillis();
for (Iterator iterator = llist.iterator(); iterator.hasNext();) {
iterator.next();
}
long lgiend = System.currentTimeMillis();
System.out.println("arraylist time get iterator:" + (lgiend - lgibegin));
long agibegin = System.currentTimeMillis();
for (Iterator iterator = alist.iterator(); iterator.hasNext();) {
iterator.next();
}
long agiend = System.currentTimeMillis();
System.out.println("linkedlist time get iterator:" + (agiend - agibegin));
}
}
复制代码
运行结果:
arraylist add time :94
linkedlist add time :93
arraylist get time :0
linkedlist get time :86969
arraylist iterator time :16
linkedlist iterator time :0