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)
| 236 | * @since 2.0 |
| 237 | */ |
| 238 | @CanIgnoreReturnValue |
| 239 | public static <T> boolean removeIf(Iterator<T> removeFrom, Predicate<? super T> predicate) { |
| 240 | checkNotNull(predicate); |
| 241 | boolean modified = false; |
| 242 | while (removeFrom.hasNext()) { |
| 243 | if (predicate.apply(removeFrom.next())) { |
| 244 | removeFrom.remove(); |
| 245 | modified = true; |
| 246 | } |
| 247 | } |
| 248 | return modified; |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Traverses an iterator and removes every element that does not belong to the |