I'm trying to remove objects from a list when it finds that particular objects privacy is private to the current user
books.eachWithIndex{ obj, i ->
if((obj.book.private).equals(true)){
def status = bookService.getBookStatus(obj.book)
if(!status){
books.remove(i)
}
}
}
error thrown as it tries to remove the object
ERROR errors.GrailsExceptionResolver - null java.util.ConcurrentModificationException
Q: is there any way to remove an object from a list within itself or would you have to separately store the index values and remove objects from outside the each loop?