Java Collection Empty isNullOrEmpty(Collection collection)

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

Description

Test a Collection for empty or null.

License

Open Source License

Parameter

Parameter Description
collection collection object to test.

Return

true if the collection is null or if the collection has no objects.

Declaration

public static boolean isNullOrEmpty(Collection collection) 

Method Source Code

//package com.java2s;
/*//from   w w  w.j av  a2s .  c  om
 * Jinx is Copyright 2010-2014 by Jeremy Brooks and Contributors
 *
 * Jinx is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Jinx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jinx.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

public class Main {
    /**
     * Test a string for empty or null.
     *
     * @param s string to test.
     * @return true if the string is null or has a trimmed length of 0.
     */
    public static boolean isNullOrEmpty(String s) {
        return s == null || s.trim().length() == 0;
    }

    /**
     * Test a Collection for empty or null.
     *
     * @param collection collection object to test.
     * @return true if the collection is null or if the collection has no objects.
     */
    public static boolean isNullOrEmpty(Collection collection) {
        return collection == null || collection.size() == 0;
    }
}

Related

  1. isNotEmptyOrNull(Collection collection)
  2. IsNotEmptyOrNull(Collection elements)
  3. isNullOrEmpty(Collection c)
  4. isNullOrEmpty(Collection c)
  5. isNullOrEmpty(Collection coll)
  6. isNullOrEmpty(Collection collection)
  7. isNullOrEmpty(Collection col)
  8. isNullOrEmpty(Collection collection)
  9. isNullOrEmpty(Collection list)