I have a Map<String, ClassA> results
.
When I do this, I get a 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);
}
});
}
})
Basically what I am trying to do is if my results, has a value of ClassA, check for each element of the list if there is any Attribute with a given key. If so, replace the values of the key with a given transformation function.
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
}
}