check List是否有相同的数据

package com.tutor.teacherservice.mybatisplus;

import com.tutor.teacherservice.entity.Person;

import java.util.*;

/**
 * @Auther Anear
 * @Date 2021/5/13
 */
public class test {
    public static void main(String[] args) {
        String b = "2";
        Integer a = (null == b || "".equals(b))?1:Integer.parseInt(b);
        System.out.println(a);
        List<Person> list = new ArrayList<>();

        Person person1 = new Person();
        person1.setName("1");
        person1.setCode("a1");

        Person person2 = new Person();
        person2.setName("1");
        person2.setCode("a2");
        Person person3 = new Person();
        person3.setName("3");
        person3.setCode("a1");
        Person person4 = new Person();
        person4.setName("3");
        person4.setCode("a1");
        list.add(person1);
        list.add(person2);
        list.add(person3);
        list.add(person4);
        boolean bool = knowledgeIsRepeat(list);
    }
    private static Boolean knowledgeIsRepeat(List<Person> orderList) {
        Set<Person> set = new TreeSet<Person>(new Comparator<Person>() {
            public int compare(Person a, Person b) {
                if(a.getName().compareTo(b.getName())== 0){
                    if(a.getCode().compareTo(b.getCode()) == 0){
                        return 0;
                    }else{
                        return a.getCode().compareTo(b.getCode());
                    }
                }else{
                    return a.getName().compareTo(b.getName());
                }
            }
        });
        set.addAll(orderList);
        if (set.size() < orderList.size()) {
            return true;
        }
        return false;
    }
}

 

posted @ 2021-06-10 10:47  根目录97  阅读(87)  评论(0编辑  收藏  举报