jdk8下 ArrayList与LinedList 排序效率对比
2021-02-06 13:17
标签:mil linedlist lis time comparing get int list cost handle total 122 array sort cost 115 jdk8下 ArrayList与LinedList 排序效率对比 标签:mil linedlist lis time comparing get int list cost 原文地址:https://www.cnblogs.com/but999/p/12781892.html总结: linkedlist排序性能更好,并且较arraylist更节省空间。
public static void main(String[] args) {
long startTime1 = System.currentTimeMillis();
List
Random r = new Random();
for (int i = 0; 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
for (int i = 0; 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 34 linked sort cost 29
文章标题:jdk8下 ArrayList与LinedList 排序效率对比
文章链接:http://soscw.com/index.php/essay/51744.html