Returns an Optional containing the first element in iterator that satisfies the given predicate, if such an element exists. If no such element is found, an empty Optional will be returned from this method and the iterator will be left exhausted: its hasNext() method w
(Iterator<T> iterator, Predicate<? super T> predicate)
| 745 | |
| 746 | |
| 747 | public static <T> Optional<T> tryFind(Iterator<T> iterator, Predicate<? super T> predicate) { |
| 748 | UnmodifiableIterator<T> filteredIterator = filter(iterator, predicate); |
| 749 | return filteredIterator.hasNext() ? Optional.of(filteredIterator.next()) : Optional.<T>absent(); |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * Returns the index in {@code iterator} of the first element that satisfies |