Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sort ArrayList of HashMaps

807603Dec 18 2007 — edited Dec 18 2007
Hello all
I have Arraylist that contains HashMaps
how can I sort the ArrayList by some value of HashMaps?

e.g. I have following HashMaps that are put inside a list and need to sort them by there value
ArrayList<HashMap> al = new ArrayList<HashMap>();

HashMap map1 = new HashMap();
map1.add( new Integer( 2 ), "two" );
map1.add( new Integer( 4 ), "four" );

HashMap map2 = new HashMap();
map2.add( new Integer( 22 ), "two2" );
map2.add( new Integer( 42 ), "four2" );

HashMap map3 = new HashMap();
map3.add( new Integer( 23 ), "two" );
map3.add( new Integer( 43 ), "four" );

al.add(map1);
al.add(map2);
al.add(map3);
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 18 2007
1 comment
669 views