Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static <E> E getFirst(Collection<E> collection, E defaultValue) {
        Iterator<E> iterator = collection.iterator();
        return iterator.hasNext() ? iterator.next() : defaultValue;
    }

    public static <E> E getFirst(Collection<E> collection) {
        return getFirst(collection, null);
    }
}