数据列表去重

2018-12-14 70 words 1 min read

Hugo搭建个人博客本人常用命令

	List list = new ArrayList<>();
	if (CollectionUtils.isNotEmpty(oldList)) {
		for (Obj obj : oldList) {
			// list去重复,内部重写equals
			if (!list.contains(obj)) {
				list.add(obj);
			}
		}
	}
	
	
     /**
     * 重写equals,用于比较对象属性是否包含
     */
    public boolean equals(Object obj) {  
        if (obj == null) {  
            return false;  
        }  
        if (this == obj) {  
            return true;  
        }  
        User user = (User) obj;  
        //多重逻辑处理,去除年龄、姓名相同的记录
        if (this.getAge().compareTo(user.getAge())==0
                && this.getUserName().equals(user.getUserName())
                && this.getScore().compareTo(user.getScore())==0) {  
            return true;  
        }  
        return false;  
    }

致谢

感谢您花时间阅读,谢谢。


Tags: repeat

author

Authored By WUHAOTIAN

A gentleman should always strive to improve himself

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it