File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Help required: sorting HashMap values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help required: sorting HashMap values" Watch "Help required: sorting HashMap values" New topic
Author

Help required: sorting HashMap values

Nidhi Singhal
Ranch Hand

Joined: Sep 19, 2004
Posts: 89

Hi,

I want to know how to sort values (not keys) in a HashMap

Thanks,
Nidhi
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

What problems did you run into while trying to do it?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You can create a list of the Map.Entry objects in the Map and sort them with a custom Comparator. See the link to the API docs in my sig for information on the Map.Entry class and the Comparator interface.

Layne


Java API Documentation
The Java Tutorial
 
jQuery in Action, 2nd edition
 
subject: Help required: sorting HashMap values