File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sort of collections by Collections.sort(..) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sort of collections by Collections.sort(..)" Watch "Sort of collections by Collections.sort(..)" New topic

Sort of collections by Collections.sort(..)

Pawanpreet Singh
Ranch Hand

Joined: Jun 12, 2005
Posts: 264

We know that we can only do sort of List by Collections.sort,

We can not do sort HashSet, HashMap and Hashtable.....because they are uordered. But LinkHashSet and LinkedHashMap are there as ordered by insertion.

So could anybody tell me that can we sort LinkHashSet and LinkedHashMap also by some way.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

If you want sorted sets and maps go for TreeMap and TreeSet.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Pankaja Shinde
Ranch Hand

Joined: Sep 15, 2006
Posts: 87
no way
we can't change the functionality of LinkedHashSet and LinkedHashMap.
I agree. Here's the link:
subject: Sort of collections by Collections.sort(..)
It's not a secret anymore!