标签:mil linedlist lis time comparing get int list cost
总结: linkedlist排序性能更好,并且较arraylist更节省空间。
public static void main(String[] args) {
long startTime1 = System.currentTimeMillis();
List<xx> arrayList = new ArrayList<>(1000);
Random r = new Random();
for (int i = 0; i < 10000; i++) {
xx a = new xx();
a.setStartTime(r.nextLong());
arrayList.add(a);
}
long startTime2 = System.currentTimeMillis();
arrayList.sort(Comparator.comparing(xx::getStartTime));
System.out.println("handle total " + (System.currentTimeMillis() - startTime1) + " array sort cost " + (System.currentTimeMillis() - startTime2));
long startTime3 = System.currentTimeMillis();
List<xx> linkedList = new LinkedList<>();
for (int i = 0; i < 10000; i++) {
xx a = new xx();
a.setStartTime(r.nextLong());
linkedList.add(a);
}
long startTime4 = System.currentTimeMillis();
linkedList.sort(Comparator.comparing(xx::getStartTime));
System.out.println("handle total " + (System.currentTimeMillis() - startTime3) + " linked sort cost " + (System.currentTimeMillis() - startTime4));
}
handle total 122 array sort cost 115
handle total 34 linked sort cost 29
jdk8下 ArrayList与LinedList 排序效率对比
标签:mil linedlist lis time comparing get int list cost
原文地址:https://www.cnblogs.com/but999/p/12781892.html