Reputation: 2971
What's the easiest way to get a distinct list of the objects using only a subset of the object's properties? I don't want to override the equals and hashCode method because this measure of object equality (i.e., a subset of the properties) is only applicable in a few use cases. Is one collection type best suited for this purpose?
Upvotes: 2
Views: 368
Reputation: 28568
Create a TreeSet and add a custom comparator that compares objects based on the subset of properties that determine uniqueness. Then add all the objects to that treeset.
Upvotes: 3