Acc. to the documents:
consider the following idiom to remove all instances of the specified element, e, from the collection, c
collection.removeAll(Collections.singleton(element));
while collection.remove(element); removes one instance of the specified item from this collection
So, to remove all instances, you must use the loop construct with the latest approach. while with the first - this is just one task per line.
source share