In this post, we will learn the difference between Iterator and ListIterator in Java. This is a frequently asked question in Java interviews for beginners. Let's dive into it.
Difference between Iterator and ListIterator in Java
Features | Iterator | ListIterator |
---|---|---|
Traversal of Types | Can traverse List, Set, and Queue types of objects | Can traverse only List type of objects |
Traversal Direction | Only in the forward direction | Both forward and backward directions |
Modifications | Can only remove elements from the collection | Can perform insertions, replacements, and removal on the list |
Iterate from Specified Index | Can't iterate a list from a specified index | Can iterate a list from a specified index |
Methods | hasNext(), next(), remove() | hasNext(), hasPrevious(), next(), previous(), nextIndex(), previousIndex(), remove(), set(), add() |
Related Collections Interview QA
- map() vs flatMap() in Java
- Collections vs Streams
- ArrayList vs Vector
- Iterator vs ListIterator
- HashMap vs HashTable
- HashSet vs HashMap
- Array vs ArrayList
- Fail-Fast Iterators vs Fail-Safe Iterators
- HashMap vs ConcurrentHashMap
- LinkedList vs ArrayDeque
- LinkedList vs Array
- LinkedList vs Doubly LinkedList
- Enum vs EnumSet in Java
- HashMap vs. TreeMap in Java
- Synchronized Collections vs. Concurrent Collections
Collection Framework
Interview Questions
Java
X vs Y
Comments
Post a Comment