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 <T> T firstElement(final Collection<T> values) {
    if (values != null && values.size() > 0) {
        return values.iterator().next();
    }/*from  w  ww  .ja  v a2s  .  c o m*/
    return null;
}

From source file:Main.java

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

From source file:Main.java

public static <T> boolean isEmpty(Collection<T> coll) {
    if (coll == null || coll.size() == 0) {
        return true;
    }/*from  w  ww  .  j  ava  2 s .c o m*/
    return false;
}

From source file:Main.java

public static String[] listToArrays(Collection<String> values) {
    String[] ret = new String[values.size()];
    values.toArray(ret);/* w  ww.ja  v  a2s.c o  m*/
    return ret;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isNotNull(Collection<?> collection) {
    if (collection != null && collection.size() > 0) {
        return true;
    }//from  w  w w  . j a v  a  2s .  c o  m
    return false;
}

From source file:Main.java

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

From source file:Main.java

/**
 * Returns <tt>true</tt> if the collection is null or contains no elements.
 *
 * @param items collection//from   w  w w.  j  av  a 2 s. c o  m
 * @return <tt>true</tt> if the collection is null or contains no elements
 */
public static boolean isEmpty(Collection items) {
    return (items == null || items.size() == 0);
}

From source file:Main.java

public static int largestList(Collection<? extends Collection> cs) {
    if (cs.isEmpty())
        return -1;
    int large = 0;
    for (Collection c : cs) {
        large = Math.max(large, c.size());
    }/*from  w  w  w  .  j av a 2s  . c  om*/
    return large;
}

From source file:Main.java

public static double[] toDoubleArray(Collection<Double> ds) {
    double[] out = new double[ds.size()];
    int index = 0;
    for (Double d : ds)
        out[index++] = d;// w ww . ja v  a 2s.  com
    return out;
}