concurrentmodification

ConcurrentModificationException when using iterator and iterator.remove()

帅比萌擦擦* 提交于 2020-01-21 08:23:06
问题 private int checkLevel(String bigWord, Collection<String> dict, MinMax minMax) { /*value initialised to losing*/ int value = 0; if (minMax == MinMax.MIN) value = 1; else value = -1; boolean go = true; Iterator<String> iter = dict.iterator(); while(iter.hasNext()) { String str = iter.next(); Collection<Integer> inds = naiveStringSearch(bigWord, str); if(inds.isEmpty()) { iter.remove(); } for (Integer i : inds) { MinMax passin = minMax.MIN; if (minMax == MinMax.MIN) passin = minMax.MAX; int

ConcurrentModificationException: .add() vs .addAll()

不打扰是莪最后的温柔 提交于 2020-01-13 04:37:13
问题 Why does the following occur? Shouldn't both work? List<String> items = data; for( String id : items ) { List<String> otherItems = otherData; // 1. addAll() //Causes ConcurrentModificationException items.addAll(otherItems); // 2. .add() //Doesn't cause exceptions for( String otherId : otherItems ) { items.add(otherId); } } Is it because add() adds to the collection Items, but addAll() creates a new collection thus modifying Items to be a different instance of List? Edit items and otherItems

map ConcurrentModificationException in for header

风流意气都作罢 提交于 2020-01-06 20:15:33
问题 I have the following code: private Multimap<Object, ComplexCalcStrategy> strategies = HashMultimap.create(); .... Collection<ComplexCalcStrategy> strategiesThatNeedUpdating = strategies.get(mktDataChange.getOptionId()); for (ComplexCalcStrategy strategy : strategiesThatNeedUpdating) { //row number 88 updateMarketData(strategy.getStrategy(), mktDataChange); } and in logs I see following trace: java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextEntry(HashMap.java

java.util.ConcurrentModificationException in ArrayList processing

99封情书 提交于 2020-01-06 15:14:24
问题 java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at com.alpha.beta.purchasing.item.VendorItemList.loadItems(VendorItemList.java:51) at com.alpha.beta.purchasing.Shipment.loadItems(Shipment.java:1006) at com.alpha.beta.purchasing.Shipment.loadItems(Shipment.java:953) at com.alpha.beta.purchasing.Shipment.getItemTotal(Shipment.java:1503) at com.alpha.beta.purchasing

Why isn't this code causing a ConcurrentModificationException? [duplicate]

不想你离开。 提交于 2020-01-02 08:56:09
问题 This question already has answers here : Why is a ConcurrentModificationException thrown and how to debug it (7 answers) Closed 10 months ago . I was reading about ConcurrentModificationException and how to avoid it. Found an article. The first listing in that article had code similar to the following, which would apparently cause the exception: List<String> myList = new ArrayList<String>(); myList.add("January"); myList.add("February"); myList.add("March"); Iterator<String> it = myList

Java HashMap add new entry while iterating

一曲冷凌霜 提交于 2020-01-01 05:02:30
问题 In a HashMap map = new HashMap<String,String>(); it = map.entrySet().iterator(); while (it.hasNext()) { entry = it.next(); it.remove(); //safely remove a entry entry.setValue("new value"); //safely update current value //how to put new entry set inside this map //map.put(s1,s2); it throws a concurrent access exception } When i trying to add a new entry to map it throws ConcurrentModificationException . For remove and update iterator has safely removing methods. How to add new entry while

ConcurrentModificationException Occuring When Retrieving List Size

坚强是说给别人听的谎言 提交于 2019-12-31 04:43:07
问题 For a project in my Data Structures class I have been tasked with creating a 3-Dimensional Range Tree where each dimension is a BST. I read this question, but it's an Android question, and the causes of our issues seem different, and the only answer was not accepted. Wall of code coming shortly. Sorry. Classes Involved: Point3D<T> : Generic class containing the coordinates for the point. T extends Comparable<T> , and Point3D extends it as well RangeTree<T> : Generic class containing the root

Guava MultiMap and ConcurrentModificationException [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-30 08:27:49
问题 This question already has answers here : Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop (24 answers) Why is a ConcurrentModificationException thrown and how to debug it (7 answers) Closed 10 months ago . I don't understand why I get a ConcurrentModificationException when I iterate through this multimap . I read the following entry, but I am not sure if I understood the whole thing. I tried to add a synchronized block. But my doubt is

Guava MultiMap and ConcurrentModificationException [duplicate]

佐手、 提交于 2019-12-30 08:27:01
问题 This question already has answers here : Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop (24 answers) Why is a ConcurrentModificationException thrown and how to debug it (7 answers) Closed 10 months ago . I don't understand why I get a ConcurrentModificationException when I iterate through this multimap . I read the following entry, but I am not sure if I understood the whole thing. I tried to add a synchronized block. But my doubt is

ConcurrentModificationException in unmodifiable collection [duplicate]

穿精又带淫゛_ 提交于 2019-12-30 08:25:12
问题 This question already has answers here : Why is a ConcurrentModificationException thrown and how to debug it (7 answers) Closed 10 months ago . I have this code below, and I'm getting a ConcurrentModificationException by executing the following line: filterCardsToDevice(getCollection()); the code: private List<MyClass> filterCardsToDevice(Collection<MyClass> col) { final List<MyClass> newList = new ArrayList<MyClass>(); for (MyClass myObj : col) { long id = myObj.getId(); if (id < 0 || id >