How to sort items in a Set?
The trick to sort a
java.util.Set is to use the implementation of a
java.util.SortedSet such as the
java.util.TreeSet class. The example below shows you the result of using the
java.util.TreeSet class, in which the items in it will be sorted based on the element's natural order.
This demo prints:
A B F H N X Z