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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: how can be retrieve from any collection into our own order?
 
Similar Threads
retrieve values randomly ?
automatic database connectivity
CMP and data retrieval
search engine to search both at database and web application level
Enumeration Object problem