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

What is the difference between remove() method of Collection and remove() method of Iterator?

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

Contents


More Related Answers

  • remove item from collection
  • Delete Collection (Get)
  • How will you efficiently remove elements while iterating a Collection?

  • What is the difference between remove() method of Collection and remove() method of Iterator?

    0

    In Collection interface remove(Object o) method is used to remove

    objects from a Collection.

    List interface also provides remove(int index) method to remove an

    object at a specific index.

    These methods are used to remove an entry from Collection, while

    no thread is iterating over it.

    When we are iterating over a Collection, then we have to remove()

    method of Iterator. This method removes current element from

    Iterator’s point of view. If we use remove(0 method of Collection

    or List, then we will get ConcurrentModificationException.

    Therefore, it is recommended to use remove() method of Iterator

    during the traversal of a Collection by an Iterator.

    https://coderanch.com/t/741104/java/iterator-remove-remove-element-collection

    Popularity 1/10 Helpfulness 3/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.