集册 Java实例教程 提供给定Iterable的第一项。

提供给定Iterable的第一项。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

394
提供给定Iterable的第一项。
/** 
来 自 
n o w j a v a . c o m
**/


//package com.nowjava;


import java.util.Iterator;


public class Main {

    /**

     * 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()) {

                
展开阅读全文