Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help required: sorting HashMap values

 
Nidhi Singhal
Ranch Hand
Posts: 89
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Thanks,
Nidhi
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problems did you run into while trying to do it?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic