aspose file tools*
The moose likes Beginning Java and the fly likes how can be retrieve from any collection into our own order? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can be retrieve from any collection into our own order?" Watch "how can be retrieve from any collection into our own order?" New topic
Author

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

Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51
Hi,
How can be retrieve elements from HashMap,TreeSet,TreeMap,Hashtable... into our own order like reverse or ascending?


Thanks in Advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Use a Comparator, or make your objects Comparable, then you can sort your collection using whatever logic you like.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

That will only work for TreeMap and TreeSet. HashMap, HashSet and Hashtable are not meant to be ordered.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: how can be retrieve from any collection into our own order?