Java List Last Item getLast(List list)

Here you can find the source of getLast(List list)

Description

Returns the last element in a list, or null if there is none.

License

Mozilla Public License

Parameter

Parameter Description
list A list.

Return

The last list element, or null if none.

Declaration

public static <T> T getLast(List<T> list) 

Method Source Code

//package com.java2s;
/**/*  w  w w  . j a va 2s.  c o m*/
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */

import java.util.List;

public class Main {
    /**
     * Returns the last element in a list, or null if there is none.
     * 
     * @param list A list.
     * @return The last list element, or null if none.
     */
    public static <T> T getLast(List<T> list) {
        return list == null || list.isEmpty() ? null : list
                .get(list.size() - 1);
    }
}

Related

  1. getLast(List aList)
  2. getLast(List elements)
  3. getLast(List items)
  4. getLast(List l)
  5. getLast(List list)
  6. getLast(List list)
  7. getLast(List list)
  8. getLast(List list)
  9. getLast(List list)