This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP 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
Marshal
Posts: 23436
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..
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!