Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;

public class Main {
    /**
     *
     * @param <T>
     * @param collection
     * @return first element or null if empty
     */
    public static <T> T getFirstElement(Collection<? extends T> collection) {
        return collection.size() > 0 ? collection.iterator().next() : null;
    }
}