如何防止我的arraylist.sort中的current并发ModificationException?

问题描述 投票:0回答:1

我正在执行某种arrayList。问题在于该方法抛出ConcurrentModificationException

这是我的代码:

void sortMyLevels(ViewModel myViewModel) {

    myViewModel.myHashMap.values().each {
        it.allLevels.sort { DoubleHelper.parseTilDouble(it.levelPrice) }
    }

}

Viewmodel具有一个称为myHashMap的映射。这些值有一个名为allLevels的列表,我想根据levelPrice进行排序。该方法引发ConcurrentModificationException。

我会很努力地尝试自己,因此我很感激能为您解决这个问题提供帮助。

grails groovy concurrentmodification
1个回答
0
投票

我认为DoubleHelper.parseTilDouble()引起了问题。它试图修改内容。如果需要,您应该首先处理地图,然后对其进行排序。排序和修改不应同时进行

© www.soinside.com 2019 - 2024. All rights reserved.