集合中存储的是对象的引用,如果对象的属性发生变化,集合中该对象也会跟着变化。
List<Student> students = new ArrayList<>();
Student student1 = new Student(4, "ying", 99);
Student student2 = new Student(5, "bing", 98);
students.add(student1);
students.add(student2);
student1.setScore(101);
System.out.println(students);