Removes every element that satisfies the provided predicate from the iterator. The iterator will be left exhausted: its hasNext() method will return false. @param removeFrom the iterator to (potentially) remove elements from @param predicate a predicate that determines whether an el
(Iterator<T> removeFrom, Predicate<? super T> predicate)
| 245 | */ |
| 246 | |
| 247 | @CanIgnoreReturnValue |
| 248 | public static <T> boolean removeIf(Iterator<T> removeFrom, Predicate<? super T> predicate) { |
| 249 | checkNotNull(predicate); |
| 250 | boolean modified = false; |
| 251 | while (removeFrom.hasNext()) { |
| 252 | if (predicate.apply(removeFrom.next())) { |
| 253 | removeFrom.remove(); |
| 254 | modified = true; |
| 255 | } |
| 256 | } |
| 257 | return modified; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Traverses an iterator and removes every element that does not belong to the |