Example usage for java.util Collection size

List of usage examples for java.util Collection size

Introduction

In this page you can find the example usage for java.util Collection size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:Main.java

public static boolean isEmpty(Collection<?> c) {
    if (c == null || c.size() == 0) {
        return true;
    }//from  w w w.j a v  a  2s.co m
    return false;
}

From source file:Main.java

/**
 * Check if the collection is empty//w w w  .j av  a  2  s  .  c om
 * 
 * @param c The collection to check.
 * @return False if the collection is not null and contains at least one element. True if the collection
 * is null, or if the collection is empty.
 */
public static boolean isEmpty(Collection<?> c) {
    if (c != null && c.size() > 0) {
        return false;
    }
    return true;
}

From source file:Main.java

/**
 * This method to check if Collection is Empty
 * @param Collection list/*w  w  w.  ja  v  a2 s .  co  m*/
 * @return boolean
 */
public static boolean isEmptyList(Collection list) {
    if (list == null || list.size() == 0) {
        return true;
    }
    return false;
}

From source file:Main.java

public static <E> int sizeOf(Collection<E> c) {
    return isEmpty(c) ? 0 : c.size();
}

From source file:Main.java

public static <T> T getSole(Collection<T> l) {
    return l.size() == 1 ? l.iterator().next() : null;
}

From source file:Main.java

public static boolean isEmpty(final Collection<?> c) {
    return (c == null) || (c.size() == 0);
}

From source file:Main.java

/**
 *
 * @param <T>//  w  w w .ja  v a  2  s.c o  m
 * @param collection
 * @return first element or null if empty
 */
public static <T> T getFirstElement(Collection<? extends T> collection) {
    return collection.size() > 0 ? collection.iterator().next() : null;
}

From source file:Main.java

public static boolean notEmpty(Collection collection) {
    return collection != null && collection.size() > 0;
}

From source file:Main.java

public static boolean isNullOrEmpty(Collection<?> list) {
    return list == null || list.size() == 0;
}

From source file:Main.java

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