List list = new ArrayList();
list.add(new Worker("凤姐", 18,20000));
list.add(new Worker("欧阳峰", 60, 8000));
list.add(new Worker("刘德华", 40, 30000));
for (int i = 0; i < list.size(); i++) {
Object obj = list.get(i);
Worker k = (Worker)obj;
if(k.getName().equals("欧阳峰")){
list.add(i++, new Worker("张柏芝", 6035, 3300)); //
}if(k.getName().equals("刘德华")){
list.remove(i);
i--;
break;
}
}
// System.out.println(list);
ListIterator lr = list.listIterator();
while(lr.hasNext()){
Object obj = lr.next();
Worker wr = (Worker)obj;
wr.work();
} |