<分区>
Possible Duplicate:
Fastest strategy to form and sort an array of positive integers
从未排序的可迭代整数中获取排序数组的最快方法是什么?目前我通过迭代可迭代 n 次(其中 n 是列表的大小)每次从可迭代中获取最高值并将其放入数组中来实现。但我希望清理它并让一些好的图书馆为我做这件事。
可能我不介意为此目的使用任何流行的库,如 Guava 等。
标签 java
<分区>
Possible Duplicate:
Fastest strategy to form and sort an array of positive integers
从未排序的可迭代整数中获取排序数组的最快方法是什么?目前我通过迭代可迭代 n 次(其中 n 是列表的大小)每次从可迭代中获取最高值并将其放入数组中来实现。但我希望清理它并让一些好的图书馆为我做这件事。
可能我不介意为此目的使用任何流行的库,如 Guava 等。
最佳答案
这与 assylias 已经提供的答案基本相同,但如果类路径上有 Google Guava,则可以将其缩短为:
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
...
List list = Lists.newArrayList(iterable);
Collections.sort(list);
关于java - 从整数的 Iterable 中获取排序数组的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13195787/