开发者

Distinct List of Objects Using a Subset of the Properties to Determine Uniqueness

开发者 https://www.devze.com 2023-03-01 04:30 出处:网络
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 e

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消