LinkedHashSet.remove() not Working?

A

Aaron Davies

I'm having a very weird problem. Under J2SE5.0b2,
LinkedHashSet.remove(Object) doesn't seem to be working right. I have
an object which I know is present in the
set--set.toArray()[0].equals(o) returns true--but set.remove(o)
returns false. If I change the collection to use a List, it all works
fine. This is bizzare. Any ideas?
 
F

Filip Larsen

Aaron Davies wrote
I'm having a very weird problem. Under J2SE5.0b2,
LinkedHashSet.remove(Object) doesn't seem to be working right. I have
an object which I know is present in the
set--set.toArray()[0].equals(o) returns true--but set.remove(o)
returns false. If I change the collection to use a List, it all works
fine. This is bizzare. Any ideas?

Perhaps the hashCode method on the object is not implemented to match
the semantics of the equals method?


Regards,
 
T

Thomas Weidenfeller

Aaron said:
I'm having a very weird problem. Under J2SE5.0b2,
LinkedHashSet.remove(Object) doesn't seem to be working right. I have
an object which I know is present in the
set--set.toArray()[0].equals(o) returns true--but set.remove(o)
returns false. If I change the collection to use a List, it all works
fine. This is bizzare. Any ideas?

You key is not immutable? Did you change it after you added it to the
hash? Is you hash code of the element changing and doesn't match your
equals() implementation?

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top