package com.sf._10_arrayList;

import java.util.ArrayList;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("张三",18,90));
        students.add(new Student("李四",17,91));
        students.add(new Student("王五",19,92));
        students.add(new Student("赵六",18,93));
        students.add(new Student("赵六",18,93));
        students.add(new Student("赵六",18,93));
        students.add(new Student("赵六",18,93));

        List<Student> sts = unqiueList(students);
        System.out.println(sts);
//        System.out.println(students);
//        for (Student student : students) {
//            if(student.getAge()  == 18){
//                System.out.println("姓名:"+ student.getName() +"语文成绩:"+ student.getChineseScore());
//            }
//        }
    }

    public static List<Student> unqiueList(List<Student> students){
        // [{zhangsan,18,80}]
        List<Student> unqiueList = new ArrayList<>();
        // [{zhangsan,18,80},{zhangsan,18,80},{lisi,18,80},,{wangwu,18,80}]
        /**
         * 第一种思路: 创建新的集合, 把之前集合内容添加新的集合中
         * 在添加之前判断判断name 是否已经存在
         */
        for (Student student : students) {
            // 判断去除集合内容是否为0 , 如果为0 ,添加任何元素都可以成功
            if(unqiueList.size() == 0){
                unqiueList.add(student);
            }else{
                // 默认值是false
                boolean flag = false;
                for (Student student1 : unqiueList) {
                    if(student1.getName().equals(student.getName())){
                        flag = true;
                    }
                }
                if(!flag){
                    unqiueList.add(student);
                }
            }
        }
        return unqiueList;
    }
}
