| |
9. 36. 8. Modifying the list that the iterator came from: add(), remove(), and set() |
|
public void add(Object element)
public void remove()
public void set(Object element)
|
|
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
public class MainClass {
public static void main(String[] a) {
List list = new LinkedList();
list.add("A");
list.add("B");
list.add("C");
list.add("D");
ListIterator iter = list.listIterator(list.size());
while (iter.hasPrevious()) {
System.out.println(iter.previous());
iter.add("a");
break;
}
System.out.println(list);
}
}
|
|
D
[A, B, C, a, D] |
|