android/guava/src/com/google/common/collect/Iterators.java
public static int size(Iterator<?> iterator) {
    long count = 0L;
    while (iterator.hasNext()) {
      iterator.next();
      count++;
    }
    return Ints.saturatedCast(count);
  }
public static int size(Iterator<?> iterator) {
    long count = 0L;
    while (iterator.hasNext()) {
      iterator.next();
      count++;
    }
    return Ints.saturatedCast(count);
  }
Returns the number of elements remaining in {@code iterator}. The iterator will be left
exhausted: its {@code hasNext()} method will return {@code false}.