guava/src/com/google/common/collect/Iterators.java
public static int frequency(Iterator<?> iterator, @Nullable Object element) {
    int count = 0;
    while (contains(iterator, element)) {
      // Since it lives in the same class, we know contains gets to the element and then stops,
      // though that isn't currently publicly documented.
      count++;
    }
    return count;
  }
public static int frequency(Iterator<?> iterator, @Nullable Object element) {
    int count = 0;
    while (contains(iterator, element)) {
      // Since it lives in the same class, we know contains gets to the element and then stops,
      // though that isn't currently publicly documented.
      count++;
    }
    return count;
  }
Returns the number of elements in the specified iterator that equal the specified object. The
iterator will be left exhausted: its {@code hasNext()} method will return {@code false}.

@see Collections#frequency