| 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
Bartender
Joined: Jan 28, 2008
Posts: 4503
|
|
|
No, you cant sort ! Use TreeSet and TreeMap instead.
|
Not everything that counts can be counted, and not everything that can be counted counts-Albert Einstein
|
 |
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: 319
|
|
|
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.
|
 |
 |
|
|
subject: Regarding LinkedHashSet and LinkedHashMap
|
|
|