Here you can find the source of size(final Iterable
Parameter | Description |
---|---|
T | The type of elements enumerated by the given iterable. |
iterable | The given iterable. |
public static <T> int size(final Iterable<T> iterable)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { /**/*from w w w . j a v a2s .c om*/ * Calculates the number of generated elements of the given iterable. * * @param <T> The type of elements enumerated by the given iterable. * @param iterable The given iterable. * @return The number of elements generated by the iterable. */ public static <T> int size(final Iterable<T> iterable) { if (iterable != null) { return size(iterable.iterator()); } else { return 0x00; } } /** * Calculates the number of generated elements of the given iterator. * * @param <T> The type of elements enumerated by the given iterator. * @param iterator The given iterator. * @return The number of elements generated by the iterator. */ public static <T> int size(final Iterator<T> iterator) { int n = 0x00; if (iterator != null) { while (iterator.hasNext()) { iterator.next(); n++; } } return n; } }