Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.annotation.Nonnull;

import java.util.Iterator;

public class Main {
    /**
     * Get the first element of a an {@link Iterable} in iteration order, or null if empty.
     *
     * @param <T> the type
     * @param iterable the thing to get something from.
     * @return the first thing the iterator spits out. May
     */
    public static <T> T first(@Nonnull final Iterable<? extends T> iterable) {
        final Iterator<? extends T> iterator = iterable.iterator();
        return (iterator.hasNext()) ? iterator.next() : null;
    }
}