*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 19651
    
  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
 
 
subject: how can be retrieve from any collection into our own order?
 
Similar Threads
Enumeration Object problem
search engine to search both at database and web application level
retrieve values randomly ?
CMP and data retrieval
automatic database connectivity