Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding LinkedHashSet and LinkedHashMap

 
anuprita rao
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cant sort ! Use TreeSet and TreeMap instead.
 
anuprita rao
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if the scjp question has sorting for these both?Is it a runtime exception?
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic