ConcurrrentModificationErro
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Line 1 is producing concurrentacesserror. How can I avoid. My requirement is that while iterating through a collection, I need to add elements to collection.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[ October 14, 2003: Message edited by: Vad Fogel ]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks for your input. I was browsing through the API documentation very briefly. My understanding is that LinkHashSet does not allow modification of base set while iterating though the set. However, listIterator of LinkedList does allow that. So I modified my program as follows and it worked:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
For example, it is not generally permssible for one thread to modify a Collection while another thread is iterating over it. In general, the results of the iteration are undefined under these circumstances. Some Iterator implementations (including those of all the collection implementations provided by the JRE) may choose to throw this exception if this behavior is detected. Iterators that do this are known as fail-fast iterators, as they fail quickly and cleanly, rather that risking arbitrary, non-deterministic behavior at an undetermined time in the future.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Iterators
As you'd expect, the Iterator returned by List's iterator operation returns the elements of the list in proper sequence. Additionally, List provides a richer iterator, called a ListIterator, that allows you to traverse the list in either direction, modify the list during iteration, and obtain the current position of the iterator. The ListIterator interface is summarized below (including the three methods it inherits from Iterator):
public interface ListIterator extends Iterator {
boolean hasNext();
Object next();
boolean hasPrevious();
Object previous();
int nextIndex();
int previousIndex();
void remove(); // Optional
void set(Object o); // Optional
void add(Object o); // Optional
}
| The only cure for that is hours of television radiation. And this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






