Java Array Empty Check isEmpty(Object[] array)

Here you can find the source of isEmpty(Object[] array)

Description

Checks whether the given Java array is empty.

License

Open Source License

Parameter

Parameter Description
array Java array to be checked.

Return

true - if the array is null or empty, false - otherwise.

Declaration

public static boolean isEmpty(Object[] array) 

Method Source Code

//package com.java2s;
/*-//from   w w w .  ja  v  a 2  s.c  o m
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

import java.util.Collection;

import java.util.Map;

public class Main {
    /**
     * Checks whether the given <tt>Object</tt> is empty.
     *
     * @param obj Object to be checked.
     * @return <tt>true</tt> - if the Object is null, <tt>false</tt> otherwise.
     */
    public static boolean isEmpty(Object obj) {
        return obj == null;
    }

    /**
     * Checks whether the given <tt>Object</tt> is empty.
     *
     * @param byteArray Object to be checked.
     * @return <tt>true</tt> - if the Object is null, <tt>false</tt> otherwise.
     */
    public static boolean isEmpty(byte[] byteArray) {
        return (byteArray == null || byteArray.length == 0);
    }

    /**
     * Checks whether the given <tt>String</tt> is empty.
     *
     * @param str String object to be checked.
     * @return <tt>true</tt> - if the String is null or empty, <tt>false</tt> - otherwise.
     */
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;
    }

    /**
     * Checks whether the given Java array is empty.
     *
     * @param array Java array to be checked.
     * @return <tt>true</tt> - if the array is null or empty, <tt>false</tt> - otherwise.
     */
    public static boolean isEmpty(Object[] array) {
        return array == null || array.length == 0;
    }

    /**
     * Checks whether the given collection is empty.
     *
     * @param collection A collection to be checked.
     * @return <tt>true</tt> - if the collection is null or empty, <tt>false</tt> - otherwise.
     */
    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    /**
     * Checks whether the given map is empty.
     *
     * @param map A map to be checked.
     * @return <tt>true</tt> - if the map is null or empty, <tt>false</tt> - otherwise.
     */
    public static boolean isEmpty(Map<?, ?> map) {
        return map == null || map.isEmpty();
    }
}

Related

  1. isEmpty(final X[] array)
  2. isEmpty(int[] array)
  3. isEmpty(int[] array)
  4. isEmpty(Object[] args)
  5. isEmpty(Object[] arr)
  6. isEmpty(Object[] array)
  7. isEmpty(Object[] array)
  8. isEmpty(Object[] array)
  9. isEmpty(Object[] array)