Vivek Modi
06/10/2022, 10:27 PMException in thread "main" java.util.ConcurrentModificationException
at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013)
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:967)
at ChipDataKt.main(ChipData.kt:72)
at ChipDataKt.main(ChipData.kt)
Vivek Modi
06/10/2022, 10:27 PMvar categoryList: MutableList<Categories>? = null
fun main() {
categoryList = categoriesList().toMutableList()
categoryList?.add(0, Categories("0", "physical-ktm", listOf(SubTopic("1", "vivek"))))
println("After Add")
categoryList?.forEachIndexed { index, categories ->
println("$index index -> $categories")
}
categoryList?.mapIndexed { index, categories ->
if(categories.subTopic?.firstOrNull()?.title == "vivek"){
categoryList?.removeAt(index)
}
}
println("After operation")
categoryList?.forEachIndexed { index, categories ->
println("$index index -> $categories")
}
}
Vivek Modi
06/10/2022, 10:27 PMfun categoriesList() = listOf(
Categories("21", "physical", listOf(SubTopic("1", "abc"), SubTopic("2", "bjhef"))),
Categories("2211", "mind", listOf(SubTopic("1", "abc"), SubTopic("2", "bjhef"))),
Categories("22131", "motorized", listOf(SubTopic("1", "abc"), SubTopic("2", "bjhef"))),
Categories("2134124", "coordination", listOf(SubTopic("1", "abc"), SubTopic("2", "bjhef"))),
Categories("211243", "animal-supported", listOf(SubTopic("1", "abc"), SubTopic("2", "bjhef"))),
)
Vivek Modi
06/10/2022, 10:27 PMdata class Categories(
val id: String? = null, val title: String? = null, val subTopic: List<SubTopic>? = null
)
data class SubTopic(
val id: String? = null, val title: String? = null, var priceId: String? = null
)
Erick Sumargo
06/10/2022, 11:49 PMfilter
? E.g:
val filteredCategoryList = categoryList?.filter { categories ->
categories.subTopic?.firstOrNull()?.title != "vivek"
}
Chrimaeon
06/11/2022, 7:03 AMChrimaeon
06/11/2022, 7:05 AMVivek Modi
06/11/2022, 8:48 AM