0

I want to remove some objects (if they meet a condition) of an ArrayList while looping through it. But that will obviously throw a 'ConcurrentModificationException'.

So, what's the best way of doing this?

edit: My condition is a number comparision, so if an objects' variable is greater than a value, the object must be removed from the list..

Robby
  • 71
  • 7

1 Answers1

1

In Java 8:

rooms.removeIf(r -> r.getSize() >= 40) ;
DevJava
  • 396
  • 1
  • 7