Java Iterable Size size(Iterable iterable)

Here you can find the source of size(Iterable iterable)

Description

size

License

Open Source License

Declaration

public static int size(Iterable<?> iterable) 

Method Source Code


//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;
    }
}

Related

  1. singleOrNull(Iterable iterable)
  2. singleOrNull(Iterable iterable)
  3. size(final Iterable iterable)
  4. size(final Iterable iterable)
  5. size(Iterable it)
  6. size(Iterable values)
  7. sizeEquals(Iterable iterable, int expectedSize)