Java Collection First getFirst(Collection set)

Here you can find the source of getFirst(Collection set)

Description

get First

License

Apache License

Declaration

public static <T> T getFirst(Collection<T> set) 

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 getFirst(Collection<T> set) {
        if (isNotEmpty(set)) {
            for (T item : set) {
                if (item != null) {
                    return item;
                }//from www.java 2  s.  c  om
            }
        }
        return null;
    }

    public static boolean isNotEmpty(Collection<? extends Object> col) {
        return col != null && col.size() > 0;
    }

    public static boolean isNotEmpty(Map<? extends Object, ? extends Object> map) {
        return map != null && map.size() > 0;
    }
}

Related

  1. getFirst(Collection collection)
  2. getFirst(Collection collection)
  3. getFirst(Collection collection)
  4. getFirst(Collection collection)
  5. getFirst(Collection l)
  6. getFirst(Collection set, boolean remove)
  7. getFirst(Collection ts)
  8. getFirst(final Collection collection)
  9. getFirstAndOnly(Collection c)