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 Spring in Action this week in the Spring 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: 19719
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can be retrieve from any collection into our own order?