Get the last value from a List - Java java.util

Java examples for java.util:List First Element

Description

Get the last value from a List

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) {
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(last(list));
    }/*from w  w w . ja  v  a  2  s. com*/

    public static <A> A last(List<A> list) {
        return list.isEmpty() ? null : list.get(list.size() - 1);
    }
}

Related Tutorials