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 double[] asDoubleArray(Collection<Double> coll) {
    double[] result = new double[coll.size()];
    int index = 0;
    for (Double element : coll) {
        result[index] = element;//from   ww w .  ja va  2 s.  co m
        index++;
    }

    return result;
}

From source file:Main.java

public static int size(Collection c) {
    return c == null ? 0 : c.size();
}

From source file:Main.java

public static <T> T getLastElement(Collection<T> collection) {
    return getElement(collection, collection.size() - 1);
}

From source file:Main.java

public static Class<?>[] asClassArray(Collection<Class<?>> coll) {
    return asArray(coll, new Class<?>[coll.size()]);
}

From source file:Main.java

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

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

From source file:Main.java

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

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> List<T> merge(Collection<T> c1, Collection<T> c2) {
    List list = new ArrayList(c1.size() + c2.size());
    list.addAll(c1);/*w ww .j a  v  a 2s. co m*/
    list.addAll(c2);
    return list;
}

From source file:Main.java

public static float[] asFloatArray(Collection<Float> collection) {
    float[] array = new float[collection.size()];
    Iterator<Float> iterator = collection.iterator();
    int i = 0;/*from   w  w  w. ja v  a 2s  . co m*/
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}

From source file:Main.java

public static String[] toStringArray(Collection<String> coll) {
    return coll.toArray(new String[coll.size()]);
}

From source file:Main.java

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