What is an Iterator ?
Answer:
The Iterator interface provides a number of methods that are able to iterate over any Collection. Each Java Collection contains the iterator method that returns an Iterator instance. Iterators are capable of removing elements from the underlying collection during the iteration. 21. What differences exist between Iterator and ListIterator ? The differences of these elements are listed below:
- An Iterator can be used to traverse the Set and List collections, while the ListIterator can be used to iterate only overLists.
- The Iterator can traverse a collection only in forward direction, while the ListIterator can traverse a List in both directions.
- The ListIterator implements the Iterator interface and contains extra functionality, such as adding an element, replacing an element, getting the index position for previous and next elements, etc.
No comments:
Post a Comment