Distinct List of Objects Using a Subset of the Properties to Determine Uniqueness
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 eq开发者_如何学Pythonuality (i.e., a subset of the properties) is only applicable in a few use cases. Is one collection type best suited for this purpose?
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.
精彩评论