Java Array Empty Check isNotEmpty(T[] array)

Here you can find the source of isNotEmpty(T[] array)

Description

Returns if the given array is null or empty.

License

Apache License

Parameter

Parameter Description
array The array to test.

Return

true if the given array is null or empty .

Declaration

public static <T extends Object> boolean isNotEmpty(T[] array) 

Method Source Code


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

import java.util.*;

public class Main {
    /**//ww  w .j  a  v a 2 s.c  o  m
     * Returns if the given {@code collection} is not {@code null} and not empty.
     *
     * @param collection
     *         The collection to test.
     * @return {@code true} if the given {@code collection} is not {@code null} and not {@code empty}.
     */
    public static <C extends Collection<?>> boolean isNotEmpty(C collection) {
        return !isEmpty(collection);
    }

    /**
     * Returns if the given {@code array} is {@code null} or empty.
     *
     * @param array
     *         The array to test.
     * @return {@code true} if the given {@code array} is {@code null} or {@code empty}.
     */
    public static <T extends Object> boolean isNotEmpty(T[] array) {
        return !isEmpty(array);
    }

    /**
     * Returns if the given {@code map} is not {@code null} and not empty.
     *
     * @param map
     *         The map to test.
     * @return {@code true} if the given {@code map} is not {@code null} and not {@code empty}.
     */
    public static <M extends Map<?, ?>> boolean isNotEmpty(M map) {
        return !isEmpty(map);
    }

    /**
     * Returns if the given {@code collection} is {@code null} or empty.
     *
     * @param collection
     *         The collection to test.
     * @return {@code true} if the given {@code collection} is {@code null} or {@code empty}.
     */
    public static <C extends Collection<?>> boolean isEmpty(C collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * Returns if the given {@code array} is {@code null} or empty.
     *
     * @param array
     *         The array to test.
     * @return {@code true} if the given {@code array} is {@code null} or {@code empty}.
     */
    public static <T extends Object> boolean isEmpty(T[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Returns if the given {@code map} is {@code null} or empty.
     *
     * @param map
     *         The map to test.
     * @return {@code true} if the given {@code map} is {@code null} or {@code empty}.
     */
    public static <M extends Map<?, ?>> boolean isEmpty(M map) {
        return map == null || map.isEmpty();
    }
}

Related

  1. isNotEmpty(Object[] arrs)
  2. isNotEmpty(Object[] ObjectArray)
  3. isNotEmpty(T[] array)
  4. isNotEmpty(T[] array)
  5. isNotEmpty(T[] array)
  6. isNotEmpty(T[] array)
  7. isNotNullAndNotEmpty(final Object[] array)
  8. isNotNullOrEmpty(T[] array)
  9. isNullOrEmpty(Object[] array)