Java List First Item firstItem(Iterable list)

Here you can find the source of firstItem(Iterable list)

Description

Provides the first item of the given list.

License

Open Source License

Parameter

Parameter Description
list the list. May be <code>null</code>.

Return

the first list item or null if the list was empty or null.

Declaration

public static <T> T firstItem(Iterable<T> list) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    /**//from w  ww .  j  a  va 2s  .  c  o m
     * Provides the first item of the given list.
     *
     * @param list the list. May be <code>null</code>.
     * @return the first list item or <code>null</code> if the list was empty or <code>null</code>.
     */
    public static <T> T firstItem(Iterable<T> list) {
        if (list != null) {
            Iterator<T> i = list.iterator();
            if (i.hasNext()) {
                return i.next();
            }
        }

        return null;
    }
}

Related

  1. first(List list)
  2. first_nItems(int n, Collection fromList)
  3. firstBoolean(List list)
  4. firstColumnRemovable(List data)
  5. firstElement(List list)
  6. firstItem(List items)
  7. firstMatch(List src, String... lookup)
  8. firstObjectFromList(List list)
  9. firstOrDefault(List items)