Jeremy Stein - Brain
« Base is null: MyBean | Maven 2 local jars » |
Java – Sort a set
Here’s my utility to method to sort a set in Java 5:
@SuppressWarnings("unchecked")
public static <T extends Comparable> List<T> asSortedList(Collection<T> collection) {
T[] array = collection.toArray(
(T[])new Comparable[collection.size()]);
Arrays.sort(array);
return Arrays.asList(array);
}
One Comment
- Keith Corlett replied:
Thank you Jeremy! I wasted a couple of hours trying to find an implementation in the core API… Yet another curious omission (IMHO).
Thanking you sir, Keith.
April 11th, 2009 at 12:32 am. Permalink.
« Base is null: MyBean | Maven 2 local jars » |
Leave a Reply