I have 2 linked lists.
I have the same object in both of those lists. By same object, I mean the object has the same state, but is referenced by a different object pointer.
I can call .remove(object);
from the first list to remove it, but if I do the same for the second list it is not removed (because the object pointer reference is different)
Is there an easy way to remove objects with the same state from various lists?
Thinking about it, I will probably loop through the second list comparing state on its objects, but I was looking for a cleaner way
Override the equals method for the object. If they have similar equivalence functionality they should be removed correctly from both lists.
Edit - for the sake of correctnes:
You should always override the hashCode method when overriding the equals method. Failure to do so may not show any strange functionality in your List but once you try to use the same object in say a HashMap, you may find that the remove or put may not function like you wanted.