• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can be retrieve from any collection into our own order?  RSS feed

 
Rahul Noel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can be retrieve elements from HashMap,TreeSet,TreeMap,Hashtable... into our own order like reverse or ascending?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a Comparator, or make your objects Comparable, then you can sort your collection using whatever logic you like.
 
Rob Spoor
Sheriff
Posts: 21116
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will only work for TreeMap and TreeSet. HashMap, HashSet and Hashtable are not meant to be ordered.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!