wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding LinkedHashSet and LinkedHashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding LinkedHashSet and LinkedHashMap" Watch "Regarding LinkedHashSet and LinkedHashMap" New topic
Author

Regarding LinkedHashSet and LinkedHashMap

anuprita rao
Greenhorn

Joined: Dec 26, 2011
Posts: 10
Can we sort both LinkedHashSet and LinkedHashMap ?Since they are ordered by insertion.Also if we can,can we use both Comparable and
Comparator?
thank you
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

No, you cant sort ! Use TreeSet and TreeMap instead.
anuprita rao
Greenhorn

Joined: Dec 26, 2011
Posts: 10
What if the scjp question has sorting for these both?Is it a runtime exception?
Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
That is a good exam tricky question. Collects.sort(...) can be used to sort a list. The parameter of the sort() methods is a List<T> , not any other type. I tried to pass a hashset to Collections.sort(), but it won't compile.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding LinkedHashSet and LinkedHashMap