public class CollectionDemo1 {
public static void main(String[] args) {
method_get();
}
public static void method_get(){
ArrayList alList=new ArrayList();
ArrayList alList1=new ArrayList();
Person p1=new Person("张珊",18);
Person p2=new Person("王五",20);
alList.add(p1.getName()+":"+p1.getAge());
alList.add(p2.getName()+":"+p2.getAge());
alList.add("java001");
Iterator it=alList.iterator();
while(it.hasNext()){
Object object=it.next();
if(object.equals("java001")){
it.remove();
}
System.out.println("原集合:"+object);
}
}
class Person{
private String name=null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
private int age=0;
Person(String name,int age) {
this.name=name;
this.age=age;
}
}
元集合输出时为啥又把删除的那个元素输出来了,求解释,最好能够详细点 |