Returns the index in iterator of the first element that satisfies the provided predicate, or -1 if the Iterator has no such elements. More formally, returns the lowest index i such that predicate.apply(Iterators.get(iterator, i)) returns true, or {
(Iterator<T> iterator, Predicate<? super T> predicate)
| 726 | * @since 2.0 |
| 727 | */ |
| 728 | public static <T> int indexOf(Iterator<T> iterator, Predicate<? super T> predicate) { |
| 729 | checkNotNull(predicate, "predicate"); |
| 730 | for (int i = 0; iterator.hasNext(); i++) { |
| 731 | T current = iterator.next(); |
| 732 | if (predicate.apply(current)) { |
| 733 | return i; |
| 734 | } |
| 735 | } |
| 736 | return -1; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Returns a view containing the result of applying {@code function} to each |