Problem with implementing removeAll for List of custom object

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-04-11T14:36:10Z Indexed on 2010/04/11 14:43 UTC
Read the original article Hit count: 490

Filed under:
|
|

Hello everyone, I have a scenario in my code where I need to compare two Lists and remove from the first list, objects which are present in the second list. Akin to how the "removeAll" object works for List. Since my List is created on a custom object, the removeAll method won't work for me.

I have tried various methods to make this work: - implemented equals() and hashCode for the custom object comprising the list - implemented the Comparable Interface for the custom object - implemented the Comparator Interface for the custom object

I've even tried using the Apache Common's CollectionUtils and ListUtils methods (subtract, intersect, removeAll). None seem to work.

I understand I will perhaps need to write some custom removal code. But not sure how to go about doing that. Any pointers helping me move in the right direction will be really appreciated.

Thanks, Jay

© Stack Overflow or respective owner

Related posts about java

Related posts about list