Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is the difference between an Iterator and ListIterator in Java?

Pragya Keshap answered on February 4, 2023 Popularity 6/10 Helpfulness 6/10

Contents


More Related Answers

  • iterator vs enumerator
  • iterator vs listiterator
  • how to use ListIterator in java
  • java list iterator example
  • difference between iterator vs enumerator
  • What is the difference between Iterator and Enumeration in Java?

  • What is the difference between an Iterator and ListIterator in Java?

    1

    Iterator and ListIterator are two interfaces in Java to traverse data

    structures. The differences between these two are:

    1. ListIterator can be used to traverse only a List. But Iterator

    can be used to traverse List, Set, and Queue etc.

    2. An Iterator traverses the elements in one direction only. It

    just goes. ListIterator can traverse the elements in two

    directions i.e. backward as well as forward directions.

    3. Iterator cannot provide us index of an element in the Data

    Structure. ListIterator provides us methods like nextIndex()

    and previousIndex() to get the index of an element during

    traversal.

    4. Iterator does not allow us to add an element to collection

    while traversing it. It throws

    ConcurrentModificationException. ListIterator allows use

    to add an element at any point of time while traversing a

    list.

    5. An existing element’s value cannot be replaced by using

    Iterator. ListIterator provides the method set(e) to replace

    the value of last element returned by next() or previous()

    methods

    https://www.geeksforgeeks.org/difference-between-an-iterator-and-listiterator-in-java/

    Popularity 6/10 Helpfulness 6/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.