Java Array Empty Check isNotEmpty(T[] array)

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

Description

Checks if an array of Objects is not empty or not null .

License

Open Source License

Parameter

Parameter Description
T the component type of the array
array the array to test

Return

true if the array is not empty or not null

Declaration

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

Method Source Code

//package com.java2s;
/*//from   w  ww .j av  a  2  s. co m
 * Copyright 2009-2012 Evun Technology. 
 * 
 * This software is the confidential and proprietary information of
 * Evun Technology. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with evun.cn.
 */

import java.util.Collection;

import java.util.Map;

public class Main {

    public static boolean isNotEmpty(Collection collection) {
        return (collection != null && !(collection.isEmpty()));
    }

    /**
     * <p>
     * Checks if an array of Objects is not empty or not {@code null}.
     * </p>
     *
     * @param <T>
     *            the component type of the array
     * @param array
     *            the array to test
     * @return {@code true} if the array is not empty or not {@code null}
     * @since 2.5
     */
    public static <T> boolean isNotEmpty(T[] array) {
        return (array != null && array.length != 0);
    }

    public static boolean isNotEmpty(int[] array) {
        return (array != null && array.length != 0);
    }

    /**
     * <p>
     * Checks if an array of primitive bytes is not empty or not {@code null}.
     * </p>
     *
     * @param array
     *            the array to test
     * @return {@code true} if the array is not empty or not {@code null}
     * @since 2.5
     */
    public static boolean isNotEmpty(byte[] array) {
        return (array != null && array.length != 0);
    }

    public static boolean isEmpty(Collection collection) {
        return (collection == null || collection.isEmpty());
    }

    /**
     * Return <code>true</code> if the supplied Map is <code>null</code> or
     * empty. Otherwise, return <code>false</code>.
     * 
     * @param map
     *            the Map to check
     * @return whether the given Map is empty
     */
    public static boolean isEmpty(Map map) {
        return (map == null || map.isEmpty());
    }

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

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

    /**
     * <p>
     * Checks if an array of primitive bytes is empty or {@code null}.
     * </p>
     *
     * @param array
     *            the array to test
     * @return {@code true} if the array is empty or {@code null}
     * @since 2.1
     */
    public static boolean isEmpty(byte[] array) {
        return array == null || array.length == 0;
    }
}

Related

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