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

Java examples for java.util:Collection First Element

Description

Returns the first item in the given collection

Demo Code


//package com.java2s;

public class Main {
    /**// w  ww  .j  ava 2 s. com
     * Returns the first item in the given collection
     */
    public static <T> T first(Iterable<T> objects) {
        if (objects != null) {
            for (T object : objects) {
                return object;
            }
        }
        return null;
    }
}

Related Tutorials