Iterator vs ListIterator

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

  1. map() vs flatMap() in Java
  2. Collections vs Streams
  3. ArrayList vs Vector
  4. Iterator vs ListIterator
  5. HashMap vs HashTable
  6. HashSet vs HashMap
  7. Array vs ArrayList
  8. Fail-Fast Iterators vs Fail-Safe Iterators
  9. HashMap vs ConcurrentHashMap
  10. LinkedList vs ArrayDeque
  11. LinkedList vs Array
  12. LinkedList vs Doubly LinkedList
  13. Enum vs EnumSet in Java
  14. HashMap vs. TreeMap in Java
  15. Synchronized Collections vs. Concurrent Collections

Comments