私にはMap<String, ClassA> results
があります。リスト内の値を編集中のJava ConcurrentModificationException
私はこれを行うと、私はConcurrentModificationExceptionを得る:基本的に
results.entrySet().stream().map((entry) -> {
ClassA objA = entry.getValue();
if(objA.getList() != null) {
objA.getList().forEach(x -> {
if(x.getAttr() != null && x.getAttr.containsKey(key)) {
List<String> y = x.getAttr().get(key);
y.replaceAll(ClassB::transformationFunc);
}
});
}
})
私がしようとしている何が私の結果は、にClassAの価値を持っている場合いずれかが存在する場合、リストの各要素をチェックしています指定されたキーを持つ属性。そうであれば、キーの値を与えられた変換関数に置き換えます。
public static String transformationFunc(String input) {
try {
JSONObject inputJson = (JSONObject) jsonParser.parse(input);
return String.format("%s_%s", inputJson.get(key1), inputJson.get(key2));
} catch (ParseException e) {
//log
//throw
}
}
[Java Concurrent Modification Exception Error](https://stackoverflow.com/questions/15384486/java-concurrent-modification-exception-error)の可能な複製 –
'ClassB :: transformationFunc'のコードを見ることができますか? –
@AlexandreDupriez transformationFuncで質問が更新されました – user1692342