开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜