Java Collection Empty isEmpty(final Collection v)

Here you can find the source of isEmpty(final Collection v)

Description

 isEmpty(null)      = true isEmpty([])        = true isEmpty([1, 2, 3]) = false 

License

Open Source License

Declaration

public static <T> boolean isEmpty(final Collection<T> v) 

Method Source Code


//package com.java2s;
/*//from   ww  w . j av  a 2  s .c  om
 * Copyright ? 2009-2011 Philipp Eichhorn.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

import java.util.Collection;

public class Main {
    /**
     * <pre>
     * isEmpty(null)  = true
     * isEmpty("")    = true
     * isEmpty("abc") = false
     * </pre>
     */
    public static boolean isEmpty(final String s) {
        return (s == null) || s.isEmpty();
    }

    /**
     * <pre>
     * isEmpty(null)               = true
     * isEmpty(new int[]{})        = true
     * isEmpty(new int[]{1, 2, 3}) = false
     * </pre>
     */
    public static <T> boolean isEmpty(final T[] v) {
        return (v == null) || (v.length <= 0);
    }

    /**
     * <pre>
     * isEmpty(null)      = true
     * isEmpty([])        = true
     * isEmpty([1, 2, 3]) = false
     * </pre>
     */
    public static <T> boolean isEmpty(final Collection<T> v) {
        return (v == null) || v.isEmpty();
    }
}

Related

  1. isEmpty(final Collection value)
  2. isEmpty(final Collection c)
  3. isEmpty(final Collection c)
  4. isEmpty(final Collection collection)
  5. isEmpty(final Collection source)
  6. isEmptyCollection(Collection collection)
  7. isEmptyCollection(Collection list)
  8. isEmptyCollection(Collection col)
  9. isEmptyCollection(Collection collection)