Alex Rivera | Logout

How to sort a Collection<T>?

Asked 2010-03-19T12:38:28.340
60

I have a generic Collection and am trying to work out how I can sort the items contained within it. I've tried a few things but I can't get any of them working.

Edit
Report

1 Answer

5

You can't if T is all you get. It must be injected by the provider:

Collection<T extends Comparable>

or pass in the Comparator

Collections.sort(...)
answered 2010-03-19T12:41:09.760

Your Answer