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;
}
}