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

/**
 * is null or its size is 0// ww w .  j  a  va 2 s. c o m
 * 
 * <pre>
 * isEmpty(null)   =   true;
 * isEmpty({})     =   true;
 * isEmpty({1})    =   false;
 * </pre>
 * 
 * @param <V>
 * @param c
 * @return if collection is null or its size is 0, return true, else return
 *         false.
 */
public static <V> boolean isEmpty(java.util.Collection<V> c) {
    return (c == null || c.size() == 0);
}

From source file:Main.java

public static boolean isEmpty(Collection collection) {
    if (collection == null || collection.size() == 0) {
        return true;
    }//from  ww w .j a v a 2s .  c  o m

    return false;
}

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E> E last(Collection<E> collection) {
    return (E) collection.toArray()[collection.size() - 1];
}

From source file:Main.java

public static boolean isEmpty(Collection<?> collection) {

    return null == collection || 0 == collection.size();
}

From source file:Main.java

public static File[] asFileArray(Collection<File> coll) {
    return asArray(coll, new File[coll.size()]);
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean allNotIn(Collection source, Collection target) {
    if (target == null || target.size() == 0) {
        return true;
    }/*from   w  ww  .  j  av  a  2s .  c o  m*/
    for (Iterator it = source.iterator(); it.hasNext();) {
        Object candidate = it.next();
        if (target.contains(candidate)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static boolean[] toBooleanArray(Collection<Boolean> c) {
    boolean arr[] = new boolean[c.size()];
    int i = 0;//from   www .  j a  va 2 s  .  co m
    for (Boolean item : c) {
        arr[i++] = item;
    }
    return arr;
}