This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
---------- java ---------- [5, 6, 7] [1, 2, 3]2 pankaj java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:448) at java.util.AbstractList$Itr.next(AbstractList.java:419) at level.removeQid(Main.java:74) at SectionLevel.removeQid(Main.java:36) at Main.main(Main.java:105) Exception in thread "main" Output completed (0 sec consumed) - Normal Termination
This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.
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.
Note that this exception does not always indicate that an object has been concurrently modified by a different thread. If a single thread issues a sequence of method invocations that violates the contract of an object, the object may throw this exception. For example, if a thread modifies a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will thow this exception.
as for as my knowledge goes, The arrayList is not a synchronized one. So concurrent operations on the object of the arraylist may result in exceptions. So u can use the synchronized objects like Vector, Hashtable. or u can get the synchronized version of the arraylist object by the methods provided in java util package