Campbell Ritchie wrote:Sets don't have an order. Can you sort a Set at all?
How about TreeSet?
But you are right about HashSet - that has no defined order, and LinkedHashSet only has insertion (and optionally access) order, nothing custom.
Paresh, you can use a List like Campbell suggested, then sort it using Collections.sort and a small set of custom java.util.Comparator implementations. Or you can create a temporary TreeSet and use its iterator. For instance: