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.Collection;

public class Main {
    public static <T> T first(Collection<? extends T> collection) {
        final T notFound = null;
        return isEmpty(collection) ? notFound : collection.iterator().next();
    }

    public static <T> boolean isEmpty(Collection<? extends T> collection) {
        return size(collection) == 0;
    }

    public static <T> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    public static int size(Collection<?> collection) {
        return collection != null ? collection.size() : 0;
    }

    public static <T> int size(T[] array) {
        return array == null ? 0 : array.length;
    }
}