How to remove non unique Objects from a List identifiable by a property?

Posted by Jennifer | Updated on

Want to remove non unique Objects from a List identifiable by a property? First of all you would need to define by which criteria the objects are supposed to be unique. Is there an identifying property for example? If that is the case the following options should work.

The most efficient way is probably to make the approach with a set working. For that you would need to turn your objects into data objects, meaning have them identify for equality by property values. For that you would override the equality operator and hashcode methods. However this changes how your objects behave on every equality operation. So you would have to judge if that is suitable. See this article.

Another option is to just filter manually using a map:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers