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

 

上一篇:js类的测试题


下一篇:十四、三目运算符、对象克隆、浅拷贝、深拷贝、模块化复习