List集合去除重复

    private Comparator<Role> roleComparator = new Comparator<Role>() {
        public int compare(Role r1, Role r2) {
            return r1.getCode().compareTo(r2.getCode());
        }
    };
 
//调用方法:
    Set<Role> results = new TreeSet<Role>(this.roleComparator);
        Iterator<Role> it = this.entity.getRoles().iterator();
 
        while (it.hasNext()) {
            Role role = (Role) it.next();
                results.add(role);
        }  
//或者:
        Set<Role> roles = new TreeSet<Role>(this.roleComparator);
            roles.addAll(selectAiUserRole.getRoles());
            
 

你可能感兴趣的:(list,集合,去重复)