Here you can find the source of getFirstNotNullValue(final Collection
Parameter | Description |
---|---|
collection | the collection to be handled. |
public static <T> T getFirstNotNullValue(final Collection<T> collection)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { /**/*from ww w . j a v a 2 s .c om*/ * Returns the first not null element if the collection is not null and have * not null value, else return null. * * @param collection * the collection to be handled. * @return the first not null element if the collection is not null and have * not null value, else null. */ public static <T> T getFirstNotNullValue(final Collection<T> collection) { if (isNotEmpty(collection)) { for (T element : collection) { if (element != null) { return element; } } } return null; } /** * Returns true if the collection is both not null and not empty; false * otherwise. * * @param collection * the collection to be tested. * @return true if the collection is both not null and not empty; false * otherwise. */ public static boolean isNotEmpty(final Collection<?> collection) { return !isEmpty(collection); } /** * Returns true if the collection is null or empty; false otherwise. * * @param collection * the collection to be tested. * @return true if the collection is null or empty; false otherwise. */ public static boolean isEmpty(final Collection<?> collection) { return collection == null || collection.isEmpty(); } }