Here you can find the source of size(Iterable> iterable)
public static int size(Iterable<?> iterable)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { public static int size(Iterable<?> iterable) { return (iterable instanceof Collection) ? ((Collection<?>) iterable).size() : size(iterable.iterator()); }//from w w w. jav a 2 s .com public static int size(Iterator<?> iterator) { int count = 0; while (iterator.hasNext()) { iterator.next(); count++; } return count; } }