package com.heima.lianxi4;
import java.util.ArrayList;
import java.util.Iterator;
import com.hema.bean.Person;
public class fgf {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList list=new ArrayList();
list.add(new Person("张三",23));
list.add(new Person("李四",24));
list.add(new Person("王五",25));
list.add(new Person("赵六",26));
Iterator lis=list.iterator();
while(lis.hasNext()){
Person p=(Person)lis.next();
if(new Person("李四",24).equals(p)){
list.add(new Person("周七",27));
}
}System.out.println(list);
}
}
package com.heima.lianxi4;
import java.util.ArrayList;
import java.util.Iterator;
import com.hema.bean.Person;
public class fgf {
/**
* @param args
*/
public static void main(String[] args) {
ArrayList list=new ArrayList();
list.add(new Person("张三",23));
list.add(new Person("李四",24));
list.add(new Person("王五",25));
list.add(new Person("赵六",26));
Iterator lis=list.iterator();
while(lis.hasNext()){
Person p=(Person)lis.next();
if(new Person("李四",24).equals(p)){
list.add(new Person("周七",27));
}
}System.out.println(list);
}
}大家知道是什么原因吗? |
|