Java Almanac and Examples Collection
The Java platform contains three general-purpose Set
implementations.
HashSet
TreeSet
LinkedHashSet
A set isn’t an ordered collection, so sorting is not available.
Manual sorting of a set
//key is id of employee
Map<Integer, Employee> map = new HashMap<Integer, Employee>();
Set<Integer> set = map.keySet();
Integer[] ids = set.toArray(new Integer[set.size()]);
Arrays.sort(ids);
for (Integer key : ids) {
//do sth
}