This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to sort a Map with Enums Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to sort a Map with Enums" Watch "How to sort a Map with Enums" New topic

How to sort a Map with Enums

vuthlarhi donald
Ranch Hand

Joined: Jul 31, 2006
Posts: 76
Iwant to sort the map, so that when I print the result's ...everything must be sorted with aphabetical order, with the ordinal values as well. so I can't use a TreeMap, because that will only sort the values of the enums/ordinal values...I am running out of

Rob Spoor

Joined: Oct 27, 2005
Posts: 19557

Use a TreeMap and provide a Comparator<Titles> or perhaps even a Comparator<Enum><?>> to the constructor.

How To Ask Questions How To Answer Questions
It is sorta covered in the JavaRanch Style Guide.
subject: How to sort a Map with Enums
Similar Threads
enum in Tiger
XML Schema design help
Enums in a map
Sorting Maps
html:options - having difficulty preselecting item