File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedHashSet question

 
Bob Novak
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone looked at the source for LinkedHashSet - it only overrides constructors on HashSet (or so it appears) in 1.4.0_03 and in 1.4.1_01.
How does this work? (i'm trying to figure out why using the addAll(Collection)/retainAll(Collection) are not working with a collection of a class that has overridden equals and hashcode...
I'm trying to implement union and intersect on a set and want to maintain the order in which they were added...
 
Bob Novak
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should've dug further
turns out that HashSet uses LinkedListMap for the HashMap used to store entries - therefore this works...
it also helps to override hashCode instead of adding a hashcode method in the entries being added to the set...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic