I have list of variants where every variant has list of colors. I want to check for every variant if has color from filter and if no, I want to remove that variant from list of variants. When I tried to remove I get error: java.util.ConcurrentModificationException This is what I tried:
list.map { variant ->
variant.variantColors.map { color ->
if (color != filterModel.color) {
list.removeIf { color != filterModel.color }
}
}
}
and:
list.map { variant ->
variant.variantColors.map { color ->
if (color != filterModel.color) {
list.removeAll { color != filterModel.color }
}
}
}
and:
val iterator = list.iterator()
while (iterator.hasNext()) {
val item = iterator.next()
val iteratorSec = item.variantColors.iterator()
while (iteratorSec.hasNext()) {
val itema = iteratorSec.next()
if (itema != filterModel.color)
iterator.remove()
}
}