Returns the last element of a list. - Java Collection Framework

Java examples for Collection Framework:List

Description

Returns the last element of a list.

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    /**/*from  www .jav a2  s .c o  m*/
     * 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);
    }
}

Related Tutorials