Possible Duplicate:
Fastest strategy to form and sort an array of positive integers
What would be the fastest way to get a sorted array from an unsorted iterable of integers ? Currently I do it by iterating over the iterable n no of times (where n is size of list) each time getting the highest from iterable & putting it in array. But I’m looking to clean this up & let some good library do it for me.
Probably I won’t mind using any popular libraries like Guava, etc for this purpose.
As commented, the easiest and probably fastest way is to populate a collection and sort it – I would simply use an ArrayList in this case:
If you know the size of your Iterable beforehand you can initialise the arraylist with the right size to make an additional efficiency gain: