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 HashMap sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "HashMap sorting " Watch "HashMap sorting " New topic
Author

HashMap sorting

thippareddy mallikarjuna reddy
Greenhorn

Joined: Mar 08, 2006
Posts: 19
Hi Friends,

This is mallikarjuna Reddy. My HashMap having key based values. some times values may be duplicate. so need to sort HashMap in the desc order. please help me in this problem.

Thanks
Mallikarjuna
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You should use a TreeMap for sorting purpose. By default it is sorted by natural-order (i.e. using the compareTo method). You could also add a Comparator to have a better control over your sorting. Checkout the TreeMap API. Example:




You could also pass your existing HashMap as an argument.




Also experiment with Comparators.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap sorting
 
Similar Threads
Tomcat Shuts down Automatically after 24hrs
order of Map
switch on String
Collection issue
First Key of HashMap