不知道怎么回事,老是有问题!帮忙看下
public class TestArrayList {
public static void main(String[] args) {
ArrayList<Student> arr = new ArrayList<>();
arr.add(new Student("张三",14));
arr.add(new Student("李四",24));
arr.add(new Student("王麻子",29));
arr.add(new Student("赵六",26));
arr.add(new Student("张三",14));
Iterator<Student> it = arr.iterator(); //Iterator( 迭代器)遍历方法
while(it.hasNext()){
System.out.println(it.next());
}
System.out.println("===========================");
for (Student st : arr) { //增强for循环
System.out.println(st);
}
System.out.println("===========================");
ListIterator<Student> listIterator = arr.listIterator();
while(listIterator.hasNext()) {
System.out.println(listIterator.next());
if((listIterator.next()).equals("张三",14)) {
listIterator.add(new Student("赵四",45));
}
}
System.out.println(arr);
}
} |
|