InterviewSolution
| 1. |
Differentiate between Iterator and ListIterator in Java. |
||||||||||||
|
Answer» In Java's Collection framework, iterators are used to obtain elements one by one. It can be used on any TYPE of Collection object. We can execute both read and remove operations using Iterator. Iterator MUST be used whenever we want to iterate elements in all Collection framework implemented interfaces, such as Set, List, Queue, and Deque, as well as all Map interface implemented classes. The only cursor accessible for the entire collection framework is the iterator. ListIterator is only useful for classes that implement List collections, such as array lists and linked lists. It can iterate in both directions. When we WISH to enumerate List elements, we must use ListIterator. This cursor has additional methods and capabilities than the iterator.
|
|||||||||||||