Here you can find the source of getIterableSize(Iterable> iterable)
public static int getIterableSize(Iterable<?> iterable)
//package com.java2s; /**//from w w w . ja va 2 s . c o m * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.md file. */ import java.util.Collection; import java.util.Iterator; public class Main { public static int getIterableSize(Iterable<?> iterable) { if (iterable instanceof Collection<?>) { return ((Collection<?>) iterable).size(); } else { Iterator<?> it = iterable.iterator(); int i = 0; while (it.hasNext()) { i++; } return i; } } }