集合中存储的是对象的引用,如果对象的属性发生变化,集合中该对象也会跟着变化。
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);
版权声明:本文为ji519974770原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。