Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.*;

public class Main {
    /**
     * Returns an arbitrary element from the given collection.
     * 
     * @param collection
     *        to retrieve the element from
     * @return an arbitrary element or <tt>null</tt> if the collection is empty
     */
    public static <T> T getAny(final Collection<T> collection) {
        final Iterator<T> iterator = collection.iterator();
        if (iterator.hasNext()) {
            return iterator.next();
        }

        return null;
    }
}