List<String> list = new ArrayList<String>();
String s1 = "hello";
String s2 = "world";
String s3 = "java";
list.add(s1);
list.add(s2);
list.add(s3);
ListIterator<String> lit = list.listIterator();
while (lit.hasNext()) {
String s = (String) lit.next();
if (s.equals("hello")) {
lit.add("javaee");
}
System.out.println(s);
}
System.out.println(list);
这里迭代器添加对象后,输出结果为
hello
world
java
[hello, javaee, world, java]
添加的"javaee"却没有被遍历输出?求解? |
|