से अधिक पुनरावृत्ति जब मैं निम्नलिखित कोड निष्पादित, मैं ConcurrentModificationExceptionजावा: ConcurrentModificationException जबकि सूची
Collection<String> myCollection = Collections.synchronizedList(new ArrayList<String>(10));
myCollection.add("123");
myCollection.add("456");
myCollection.add("789");
for (Iterator it = myCollection.iterator(); it.hasNext();) {
String myObject = (String)it.next();
System.out.println(myObject);
myCollection.remove(myObject);
//it.remove();
}
क्यों मैं अपवाद हो रही है, भले ही मैं Collections.synchronizedList उपयोग कर रहा हूँ?
जब मैं
ConcurrentLinkedQueue<String> myCollection = new ConcurrentLinkedQueue<String>();
को myCollection बदल रहा है कि अपवाद नहीं मिलता है।
संग्रह.सिंक्रनाइज़लिस्ट सूची से अलग java.util.concurrent में ConcurrentLinkedQueue कैसे है?
[एक संग्रह के माध्यम से बार-बार दोहराना, ConcurrentModificationException परहेज जब पाश में दूर करने] (http://stackoverflow.com/questions/223918/iterating-through-a-collection-avoiding-concurrentmodificationexception-when-re) – Raedwald