JavaIntermediate#collections

What is the difference between Iterator and ListIterator?

Iterator supports forward-only traversal and removal for any Collection. ListIterator (for List only) supports bidirectional traversal, element replacement (set()), and index-aware insertion.

Example
ListIterator<String> it = list.listIterator();
while (it.hasNext()) {
  String s = it.next();
  if (s.equals("x")) it.set("y"); // replace in place
}

Related Questions

1
JavaIntermediate#collections

What is the difference between Deque and Queue?

Open
2
JavaBeginner#collections

How do you make a collection immutable?

Open
3
JavaBeginner#collections

What is the difference between Collection and Collections?

Open