• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to sort the tree map in collections?  RSS feed

 
shaik yaseen
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?
 
Henry Wong
author
Sheriff
Posts: 23295
125
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
 
Winston Gutkowski
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
 
Satheesh chandragupthan
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!