I got an issue with deleting an object from ArrayList when working on the assignment If I use the "normal" for loop, it works as following
public void returnBook(String isbn){
for (int i = 0; i < booksBorrowed.size(); i++){
if (booksBorrowed.get(i).getISBN() == isbn){
booksBorrowed.get(i).returnBook();
booksBorrowed.remove(i);
}
}
}
However, when I'm trying to simplify the code with enhanced for-loop, that doesn't work and showing java.util.ConcurrentModificationException error:
public void returnBook(String isbn){
for (Book book: booksBorrowed){
if (book.getISBN() == isbn){
book.returnBook();
booksBorrowed.remove(book);
}
}
}
Hope you guys could lighten me up..