Java Array Element Get getlast(final T[] array)

Here you can find the source of getlast(final T[] array)

Description

getlast

License

Apache License

Parameter

Parameter Description
array an array (may be null or empty)

Return

the last element of array if any, null otherwise.

Declaration

public static <T> T getlast(final T[] array) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**//from  w ww.  j  a v  a  2s  .  c  o m
     * @param array an array (may be null or empty)
     * @return the last element of <code>array</code> if any, <code>null</code> otherwise.
     */
    public static <T> T getlast(final T[] array) {
        return array == null || array.length == 0 ? null : array[array.length - 1];
    }

    /**
     * @param list a list (may be null or empty)
     * @return the last element of <code>list</code> if any, <code>null</code> otherwise.
     */
    public static <T> T getlast(List<T> list) {
        return list == null || list.size() == 0 ? null : list.get(list.size() - 1);
    }
}

Related

  1. getArrays(byte[] inputArray, int arraySize, boolean zeroPad)
  2. getArraySubset(T[] array, int start, int end)
  3. getFrequentElement(int[] bcp)
  4. getFrequentElement(int[] bcp)
  5. getItems(T[] items, int[] indices)
  6. getLast(T[] l)
  7. tail(int[] original)
  8. tail(Object[] array)