How to remove duplicate objects in a List without equals/hashcode?

后端 未结 21 1645
渐次进展
渐次进展 2020-12-03 02:53

I have to remove duplicated objects in a List. It is a List from the object Blog that looks like this:

public class Blog {
    private String title;
    priv         


        
21条回答
  •  误落风尘
    2020-12-03 03:15

    The easiest and the most effective way would be to allow eclipse to generate and override the equals and hashcode method. Just select the attributes to be checked for duplicates when prompted and you should be all set.

    Also once the list is ready, put it into a Set and you have the duplicates gone.

提交回复
热议问题