This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to sort the tree map in collections?  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which is the best way to sort the tree map either key or by value?
 
author
Sheriff
Posts: 23554
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

shaik yaseen wrote:which is the best way to sort the tree map either key or by value?



I don't think that there is an an option. The key-value pairs are sorted by the key.

Henry
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

shaik yaseen wrote:which is the best way to sort the tree map either key or by value?


A TreeMap is already "sorted" by key. If the values are Comparable, then you can get a sorted List of them with:otherwise, you'll have to use a Comparator.

Winston
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
key and value are the pair..each pair is called entry.

if you want to sort the values then sort the values..
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!