Java List Last Item removeLast(List aList)

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

Description

Removes the last object from given list.

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**/*from   w  ww.j av  a2  s.co m*/
     * Removes the last object from given list.
     */
    public static <T> T removeLast(List<T> aList) {
        return aList.remove(aList.size() - 1);
    }

    /**
     * Removes given object from given list (accepts null list).
     */
    public static boolean remove(List aList, Object anObj) {
        return aList == null ? false : aList.remove(anObj);
    }

    /**
     * Removes range of objects from given list (from start to end, not including end).
     */
    public static void remove(List aList, int start, int end) {
        for (int i = end - 1; i >= start; i--)
            aList.remove(i);
    }

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

Related

  1. lastIndexOf(List lines, String... conditions)
  2. lastIndexOfIdentical(List l, T element, int startingAt)
  3. listToWorkspaceLocationHistoryString(List lastUsedWorkspaceLocationList)
  4. removeBySwapLast(List a, Object o)
  5. removeLast(List list)
  6. removeLast(List l)
  7. removeLast(List list)
  8. removeLastElements(List list, int fromIdx)