Java Collection Empty isNotEmpty(Collection collection)

Here you can find the source of isNotEmpty(Collection collection)

Description

Check if collection is not null and not empty

License

Apache License

Parameter

Parameter Description
collection Collection to check

Return

empty or not

Declaration

public static <T> boolean isNotEmpty(Collection<T> collection) 

Method Source Code

//package com.java2s;
/*// w w w.  j av  a2  s .  c om
 * Copyright 2015 52?North Initiative for Geospatial Open Source
 * Software GmbH
 *
 * 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.
 */

import java.util.Collection;

import java.util.Map;

public class Main {
    /**
     * Check if collection is not null and not empty
     *
     * @param collection
     *            Collection to check
     *
     * @return empty or not
     */
    public static <T> boolean isNotEmpty(Collection<T> collection) {
        return !isEmptyOrNull(collection);
    }

    /**
     * Check if collection is not null and not empty
     *
     *
     * @param map
     *            Map to check
     *
     * @return <tt>false</tt>, if map is <tt>null</tt> or empty, else
     *         <tt>true</tt>.
     */
    public static <K, V> boolean isNotEmpty(Map<K, V> map) {
        return map != null && !map.isEmpty();
    }

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

    /**
     * Check if collection is not <tt>null</tt> and empty
     *
     * @param collection
     *            Collection to check
     *
     * @return <tt>true</tt>, if collection is not null and empty, else
     *         <tt>false</tt>
     */
    public static <T> boolean isEmpty(Collection<T> collection) {
        return collection != null && collection.isEmpty();
    }

    /**
     * Check if map is not <tt>null</tt> and empty
     *
     * @param map
     *            map to check
     *
     * @return <tt>true</tt>, if map is not null and empty, else <tt>false</tt>
     */
    public static <K, V> boolean isEmpty(Map<K, V> map) {
        return map != null && map.isEmpty();
    }
}

Related

  1. isNotEmpty(Collection collection)
  2. isNotEmpty(Collection source)
  3. isNotEmpty(Collection values)
  4. isNotEmpty(Collection... colls)
  5. isNotEmpty(Collection collection)
  6. isNotEmpty(Collection values)
  7. isNotEmpty(E collection)
  8. isNotEmpty(final Collection coll)
  9. isNotEmpty(final Collection collection)