Here you can find the source of firstItem(Iterable
Parameter | Description |
---|---|
list | the list. May be <code>null</code>. |
null
if the list was empty or null
.
public static <T> T firstItem(Iterable<T> list)
//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; } }