Java Collection First firstNonNull(Collection collection)

Here you can find the source of firstNonNull(Collection collection)

Description

first Non Null

License

Open Source License

Declaration

public static <E> E firstNonNull(Collection<E> collection) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    public static <E> E firstNonNull(Collection<E> collection) {
        return firstNonNull(collection, null);
    }/*from  w w w . j  a  v a2s .  co  m*/

    public static <E> E firstNonNull(Collection<E> collection, E defaultValue) {
        for (E element : collection) {
            if (element != null) {
                return element;
            }
        }
        return defaultValue;
    }
}

Related

  1. firstElementOf(final Collection collection)
  2. firstElementOf(final Collection items)
  3. firstFrom(Collection collection)
  4. firstFrom(Collection coll)
  5. firstNonEmpty(Collection... collections)
  6. firstOrThat(Collection collection, T that)
  7. firstValue(Class type, Collection values)
  8. GET_FIRST_ELEMENT(Collection coll)
  9. getCollectionFirstElement( final Collection collection)