aspose file tools*
The moose likes Java in General and the fly likes Sort a Map on the <Key>. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sort a Map on the <Key>." Watch "Sort a Map on the <Key>." New topic
Author

Sort a Map on the <Key>.

Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hello,

How do we sort a <Map> on the key? I am using a java.util.HashMap.

Thanks,
Raj.
pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 413

I think you can use TreeMap


Pawan Chopra
SCJP - DuMmIeS mInD
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Dump the HashMap into a TreeMap:

Map hashMap= new HashMap();
Map sortedMap = new TreeMap(hashMap);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sort a Map on the <Key>.