Java Iterable Size singleOrNull(Iterable iterable)

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

Description

A single item or null

License

Apache License

Parameter

Parameter Description
iterable The iterable
T The item

Return

A single item or null

Declaration

public static <T> T singleOrNull(Iterable<T> iterable) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Iterator;

public class Main {
    /**// ww w .  java2 s  .c o m
     * A single item or null
     *
     * @param iterable The iterable
     * @param <T> The item
     * @return A single item or null
     */
    public static <T> T singleOrNull(Iterable<T> iterable) {
        Iterator<T> i = iterable.iterator();
        if (i.hasNext()) {
            return i.next();
        }
        return null;
    }
}

Related

  1. getSingleIfExist(Iterable iterable)
  2. getSingleOrNull(Iterable iterable)
  3. iterableSize(Iterable iterable)
  4. iterableSize(Iterable itrbl)
  5. iterableSizeEq(Iterable itrbl, int k)
  6. singleOrNull(Iterable iterable)
  7. size(final Iterable iterable)
  8. size(final Iterable iterable)
  9. size(Iterable it)