aspose file tools*
The moose likes Java in General and the fly likes LinkedHashSet question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "LinkedHashSet question" Watch "LinkedHashSet question" New topic

LinkedHashSet question

Bob Novak

Joined: Oct 25, 2001
Posts: 8
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

Joined: Oct 25, 2001
Posts: 8
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...
I agree. Here's the link:
subject: LinkedHashSet question
Similar Threads
How to print a String with out duplicates
order of elements returned by Iterator in Set
hashcode() and equals()