集册 Java实例教程 返回列表的最后一个元素。

返回列表的最后一个元素。

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

458
返回列表的最后一个元素。


//package com.nowjava;/** from 时 代      J a v a   公   众 号 - nowjava.com**/


import java.util.List;


public class Main {

    /**

     * Returns the last element of a list.

     *

     * @param <T> Type of the objects in the input list.

     * @param list The input list.

     *

     * @return The last element of the input list.

     */

    public static <T> T last(final List<T> list) {

        return list.get(list.size() - 1);

    }

}