Java List Last Item getLast(List aList)

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

Description

Returns the last object in the given list.

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**/*from  www .  j a v  a 2s .  c  o m*/
     * Returns the last object in the given list.
     */
    public static <T> T getLast(List<T> aList) {
        return get(aList, size(aList) - 1);
    }

    /**
     * Returns the object at the given index (returns null object for null list or invalid index).
     */
    public static <T> T get(List<T> aList, int anIndex) {
        return aList == null || anIndex < 0 || anIndex >= aList.size() ? null : aList.get(anIndex);
    }

    /**
     * Returns the size of a list (accepts null list).
     */
    public static int size(List aList) {
        return aList == null ? 0 : aList.size();
    }
}

Related

  1. buildPathFromComponentsUpToIndex(final List pathComponents, final int lastIndex)
  2. flattenByteSegments(List byteSegments, int eachSegmentButLastLength, int lastSegmentLength)
  3. getLast(final List list)
  4. getLast(final List list)
  5. getLast(List list)
  6. getLast(List elements)
  7. getLast(List items)
  8. getLast(List l)
  9. getLast(List list)