list中有重复数据 进行去重

 private static List<Comment> removeDuplicateInvoice(List<Comment> comment) {
        List<Comment> list = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(comment)) {
            for (Comment co : comment) {
                //list去重复,内部重写equals
                if (!list.contains(co)) {
                    list.add(co);
                }
            }
        }
        System.out.println(list);
        return list;
    }

Comment实体类中要加入方法比较

public class Comment {
    private  String publishTime;
    private String targetUrl;
    private Integer id;
    private String targetName;
    private List<Person> replayList;
    private  String  content;
    private String replayLists;
    private Integer categoryId;

    private String category;

    @Override
    public String toString() {
        return "Comment{" +
                "publishTime='" + publishTime + '\'' +
                ", targetUrl='" + targetUrl + '\'' +
                ", id=" + id +
                ", targetName='" + targetName + '\'' +
                ", replayList=" + replayList +
                ", content='" + content + '\'' +
                ", replayLists='" + replayLists + '\'' +
                ", categoryId=" + categoryId +
                ", category='" + category + '\'' +
                '}';
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getReplayLists() {
        return replayLists;
    }

    public void setReplayLists(String replayLists) {
        this.replayLists = replayLists;
    }

    public String getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(String publishTime) {
        this.publishTime = publishTime;
    }

    public String getTargetUrl() {
        return targetUrl;
    }

    public void setTargetUrl(String targetUrl) {
        this.targetUrl = targetUrl;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTargetName() {
        return targetName;
    }

    public void setTargetName(String targetName) {
        this.targetName = targetName;
    }

    public List<Person> getReplayList() {
        return replayList;
    }

    public void setReplayList(List<Person> replayList) {
        this.replayList = replayList;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        Comment user = (Comment) obj;
        if (this.getContent() .equals(user.getContent())
                && this.getTargetName().equals(user.getTargetName())
                && this.getTargetUrl().equals(user.getTargetUrl())
                &&this.getPublishTime().equals(user.getPublishTime())
                ){
            return true;
        }
        return false;
    }


}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值