public class Test1 {
public static void main(String[] args) {
ArrayList<Student> arr = new ArrayList<Student> ();
Student s1=new Student("风清扬",23);
Student s2=new Student("刘意",24);
Student s3=new Student("冯佳",18);
Student s4=new Student("周星驰",19);
Student s5=new Student("老毕",19);
Student s6=new Student("周星驰",19);
Student s7=new Student("刘意",24);
arr.add(s1);
arr.add(s2);
arr.add(s3);
arr.add(s4);
arr.add(s5);
arr.add(s6);
arr.add(s7);
for (int i = 0; i < arr.size(); i++) {
for (int j = 0; j < i; j++) {
if (arr.get(i).equals(arr.get(j))) {
arr.remove(j);
}
}
}
for(Student s:arr){
System.out.println(s.getName()+"---"+s.getAge());
}
}
}
我比较String类型的就可以,为什么比较对象就不行了呢 |