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!

TreeMap Sorting by Keys then Values

807580Dec 21 2009 — edited Dec 22 2009
Is there anyway to sort a TreeMap via it's keys and values?

I have a TreeMap where keys are strings and values are integers. I wish to sort via the highest value, and then the key alphabetically.

For example,

treemap.put("test", 5);
treemap.put("hello", 5);
treemap.put("face", 1);
treemap.put("inout", 8);

How can I make the output

inout - 8
hello - 5
test - 5
face - 1

At the moment, it just sorts the keys alphabetically.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 19 2010
Added on Dec 21 2009
2 comments
395 views