Reputation: 237
I have a HashMap and I need sort him by key. What must I do? If you will give me example than I will be glad. Thank you for, anyway.
Upvotes: 1
Views: 780
Reputation: 597076
Pick an implementation of SortedMap
(for example TreeMap
), and :
Comparable
use use the copy-constructor (new TreeMap(existingMap)
) to put your existing map elements to the sorted map.TreeMap
with a Comparator
and then use treeMap.addAll(existingMap)
Upvotes: 5