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 {
    /**
     * Checks to see if an array is not empty
     * <p>
     * An empty array is one that is null or has zero elements.  Everything else is
     * considered non-empty.
     * </p>
     *
     * @param array The array to check
     * @param <T>   The type of the array
     * @return true if the collection not empty, false otherwise
     */
    public static <T> boolean isNotEmpty(T[] array) {
        return !isEmpty(array);
    }

    /**
     * Checks to see if a collection is populated
     * <p>
     * An empty collection is one that is null or has zero elements.  Everything else is
     * considered non-empty.
     * </p>
     *
     * @param collection The collection to check
     * @param <T>        The type of the collection
     * @return true if the collection is not null and has at least one element, false otherwise
     */
    public static <T> boolean isNotEmpty(Collection<T> collection) {
        return !isEmpty(collection);
    }

    /**
     * Checks to see if an array is empty
     * <p>
     * An empty array is one that is null or has zero elements.  Everything else is
     * considered non-empty.
     * </p>
     *
     * @param array The array to check
     * @param <T>   The type of the array
     * @return true if the collection is null or empty, false otherwise
     */
    public static <T> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Checks to see if a collection is empty
     * <p>
     * An empty collection is one that is null or has zero elements.  Everything else is
     * considered non-empty.
     * </p>
     *
     * @param collection The collection to check
     * @param <T>        The type of the collection
     * @return true if the collection is null or empty, false otherwise
     */
    public static <T> boolean isEmpty(Collection<T> collection) {
        return collection == null || collection.isEmpty();
    }
}