Ad
  • Custom User Avatar

    I understand, thank you for the explanation!

  • Custom User Avatar
    1. This can be changed by making a copy of the input parameter and working on that.

    2. The problem with the iterator is that you would need a cyclic iterator, or starting iterating over and over again.

  • Custom User Avatar

    The reason why you should not remove or add an element from a collection while iterating it is the iterating method might throw a Concurrent exception. But the code here only calls for List.size() which is ok.

  • Custom User Avatar

    Removeing items from a list with 'items.remove((int) position)' is bad in two ways:

    1. do not modify input parameters
    2. it is expensive for LinkedList (seek to the element) or ArrayList (copy a large area)

    What do you think about an iterator on a LinkedList?

  • Custom User Avatar

    I'm curious: How can this work?

    Isn't removing items from a list forbidden while you are traversing it?
    A ConcurrentModificationException should be thrown, and therefore, you would need to use iterators to be able to remove elements from the list you are traversing.

  • Default User Avatar

    yep still getting this error