I am programming a sorting system to school that must split some people into two cars, but I am stuck and I don't know how to continue.
When I delete the second when, it was working. But I need it there so I don't know what to do.
I already tried iterators but I am new in kotlin and it didn't work.
for (firstPeople in firstCar){
when {
k.contains(firstPeople.toString()) -> secondCar.add(j)
// println(secondCar)
k.contains(firstPeople.toString()) -> firstCar.add(j)
// println(firstCar)
else -> when {
firstCar.size > secondCar.size -> secondCar.add(j)
firstCar.size < secondCar.size -> firstCar.add(j)
else -> firstCar.add(j)
}
}
}
Error:
Exception in thread "main" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.next(ArrayList.java:859)
at MainKt.main(Main.kt:65)
at MainKt.main(Main.kt)
Thank you so much for the answer.