package com.heima.test;
import java.util.ArrayList;
import java.util.Iterator;
public class Test_1 {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList<Person> al = new ArrayList<>();
al.add(new Person("张三", 23));
al.add(new Person("张三", 23));
al.add(new Person("李四", 24));
al.add(new Person("李四", 24));
al.add(new Person("李四", 24));
al.add(new Person("李四", 24));
ArrayList<Person> newal = new ArrayList<>();
Iterator<Person> it = newal.iterator();
while (it.hasNext()) {
Person p = it.next();
if (!newal.contains(p)) {
newal.add(p);
}
}
System.out.println(newal);
}
}
哪儿有问题呢?怎么打印是空呢? |
|