Java Collection First first(Collection collection)

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

Description

first

License

Apache License

Declaration

public static <T> T first(Collection<? extends T> collection) 

Method Source Code


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

import java.util.Collection;

public class Main {
    public static <T> T first(Collection<? extends T> collection) {
        final T notFound = null;
        return isEmpty(collection) ? notFound : collection.iterator().next();
    }/*  www  . j a va2 s  .c o  m*/

    public static <T> boolean isEmpty(Collection<? extends T> collection) {
        return size(collection) == 0;
    }

    public static <T> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    public static int size(Collection<?> collection) {
        return collection != null ? collection.size() : 0;
    }

    public static <T> int size(T[] array) {
        return array == null ? 0 : array.length;
    }
}

Related

  1. first(Collection collection)
  2. first(Collection collection)
  3. first(Collection items)
  4. first(Collection collection, E alternative)
  5. first(Collection collection)
  6. first(Collection values)
  7. first(Collection collection)
  8. first(Collection self)
  9. first(Collection c)