This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help required: sorting HashMap values
 
Similar Threads
WA #1.....word association
Collection issue
switch on String
hashmap with null values and keys
when the HashMap instance need synchronized?