Returns the last item in the given collection - Java java.util

Java examples for java.util:Collection First Element

Description

Returns the last item in the given collection

Demo Code


//package com.java2s;

public class Main {
    /**/*from   ww w  . j  a v  a 2  s .  c o  m*/
     * Returns the last item in the given collection
     */
    public static <T> T last(Iterable<T> objects) {
        T answer = null;
        if (objects != null) {
            for (T object : objects) {
                answer = object;
            }
        }
        return answer;
    }
}

Related Tutorials