• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
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
Pie
Posts: 20512
54
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