How to sort hashmap?

Posted by agazerboy on Stack Overflow See other posts from Stack Overflow or by agazerboy
Published on 2010-01-03T04:01:22Z Indexed on 2010/03/13 18:15 UTC
Read the original article Hit count: 598

Filed under:
|

Hi All !

I have hashmap and its keys are like "folder/1.txt,folder/2.txt,folder/3.txt" and value has these text files data.

Now i am stucked. I want to sort this list. But it does not let me do it :( Here is my hashmap data type:

HashMap<String, ArrayList<String>> 

following function work good but it is for arraylist not for hashmap.

Collections.sort(values, Collections.reverseOrder());

I also tried MapTree but it also didn't work, or may be I couldn't make it work. I used following steps to sort the code with maptree

HashMap testMap = new HashMap();
Map sortedMap = new TreeMap(testMap);

any other way to do it??

I have one doubt as my keys are (folder/1.txt, folder/2.txt ) may be that's why?

© Stack Overflow or respective owner

Related posts about java

Related posts about hashmap