Size of Iterable<Type>

generics, iterable, java

Solution

You can check if the an `Iterable` is empty using `iterator().hasNext()`.

    Iterable<Type> i = /* assigned somehow */;
    i.iterator().hasNext();

Problem

Suppose a method returns `Iterable<Type>`. Is there a more elegant and efficient way to check whether what is returned is empty (or of some given size) than what I'm doing now? ``` int i = 0; for (Type dummy : method) i++; if (i == 0) ... ```

Original source