ArrayList还是LinkedList更适合排序? [英] Is an ArrayList or a LinkedList better for sorting?
问题描述
我想使用需要逐个排序的数据结构。数据结构的大小几乎不会超过1000项。
哪一个更好 - ArrayList
或 LinkedList
?
哪种排序算法更好用?
由于 Collections.sort
将库列表的内容转储为数组,所以没有任何区别。 >
使用Java 8,使用 ArrayList
应该稍快一些,因为 Collections.sort
将调用 List.sort
和 ArrayList
具有专门的版本,直接排列支持数组,保存副本
所以底线是 ArrayList
更好,因为它给出类似或更好的性能,具体取决于Java的版本。
I want to use data structure that needs to be sorted every now and again. The size of the data structure will hardly exceed 1000 items.
Which one is better - ArrayList
or LinkedList
?
Which sorting algorithm is better to use?
Up to Java 7, it made no difference because Collections.sort
would dump the content of the list into an array.
With Java 8, using an ArrayList
should be slightly faster because Collections.sort
will call List.sort
and ArrayList
has a specialised version that sorts the backing array directly, saving a copy.
So bottom line is ArrayList
is better as it gives a similar or better performance depending on the version of Java.
这篇关于ArrayList还是LinkedList更适合排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!