Java Collection First firstFrom(Collection coll)

Here you can find the source of firstFrom(Collection coll)

Description

first From

License

Apache License

Declaration

public static <T> T firstFrom(Collection<T> coll) 

Method Source Code

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

import java.util.Collection;

import java.util.Map;

public class Main {
    public static <T> T firstFrom(Collection<T> coll) {
        if (isEmpty(coll))
            return null;
        return coll.iterator().next();
    }//from   ww w . j a  v a  2  s . c o m

    public static boolean isEmpty(Object o) {
        return o == null;
    }

    public static boolean isEmpty(Collection<?> col) {
        return col == null || col.size() == 0;
    }

    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.size() == 0;
    }

    public static boolean isEmpty(Object[] arr) {
        return arr == null || arr.length == 0;
    }
}

Related

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