Java Utililty Methods Iterable Size

List of utility methods to do Iterable Size

Description

The list of methods to do Iterable Size are organized into topic(s).

Method

TsingleOrNull(Iterable iterable)
Method returns the single element from an iterable or null if empty iterable is passed.
if (iterable == null) {
    throw new IllegalArgumentException("Null is not a valid argument for this method");
Iterator<T> iterator = iterable.iterator();
if (!iterable.iterator().hasNext()) {
    return null;
} else {
    T element = iterator.next();
...
intsize(final Iterable iterable)
Returns size of iterable.
return (iterable instanceof Collection) ? ((Collection<?>) iterable).size() : size(iterable.iterator());
intsize(final Iterable iterable)
Calculates the number of generated elements of the given iterable.
if (iterable != null) {
    return size(iterable.iterator());
} else {
    return 0x00;
intsize(Iterable it)
Count statements in iterable 'it'
int count = 0;
Iterator<?> i = it.iterator();
while (i.hasNext()) {
    i.next();
    count++;
return count;
intsize(Iterable iterable)
size
return (iterable instanceof Collection) ? ((Collection<?>) iterable).size() : size(iterable.iterator());
intsize(Iterable values)
Returns the number of elements in the Iterable .
if (values instanceof Collection<?>) {
    return ((Collection<?>) values).size();
int count = 0;
for (Iterator<?> it = values.iterator(); it.hasNext(); ++count) {
    it.next();
return count;
...
booleansizeEquals(Iterable iterable, int expectedSize)
size Equals
Iterator<T> iterator = iterable.iterator();
int currentSize = 0;
while (iterator.hasNext()) {
    if (expectedSize > currentSize) {
        currentSize++;
        iterator.next();
        continue;
    } else {
...