Java - Distinct List of Objects

后端 未结 9 923
不知归路
不知归路 2020-12-05 09:41

I have a list/collection of objects that may or may not have the same property values. What\'s the easiest way to get a distinct list of the objects with equal properties? I

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 10:34

    Java 8:

    recipients = recipients.stream()
        .distinct()
        .collect(Collectors.toList());
    

    See java.util.stream.Stream#distinct.

提交回复
热议问题