Here you can find the source of size(Iterator
public static <T> long size(Iterator<T> iterator)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { public static <T> long size(Iterator<T> iterator) { long size = 0; while (iterator.hasNext()) { iterator.next();/* ww w. j ava 2 s . co m*/ size += 1; } return size; } }