Rob Prime wrote:When you access an object, the set uses the hashCode of the object to determine the bucket. It then goes through the linked list using equals.
If you use the default hashCode implementation of Object, then it will most likely look in the wrong bucket. It there will not find an object that is equal, so nothing is found.
Campbell Ritchie wrote:I am afraid it might not help; she was asking last November. Please look at this FAQ.
Rob Prime wrote:
Those Java statements won't compile; the bulk methods do not return a set but a boolean. The statements should be as followed (of course the Set implementation can change):
Rob Prime wrote:
Almost right. With HashSet and LinkedHashSet, you need to override both equals and hashCode. For TreeSet, you can go two ways:
- have your classes implement Comparable
- use a custom Comparator