Here you can find the source of singleOrNull(Iterable
Parameter | Description |
---|---|
iterable | The iterable |
T | The item |
public static <T> T singleOrNull(Iterable<T> iterable)
//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; } }