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 String[] toArray(Collection<String> c) {
    return c.toArray(new String[c.size()]);
}

From source file:Main.java

/**
 * @return een int array van alle elementen uit de <tt>collection</tt>.
 *//* www  . j a va  2  s . c om*/
public static int[] toIntArray(Collection<Integer> collection) {
    int[] res = new int[collection.size()];
    Iterator<Integer> iterator = collection.iterator();
    for (int i = 0; i < collection.size(); i++) {
        res[i] = iterator.next();
    }
    return res;
}

From source file:Main.java

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

From source file:Main.java

public static <T> String[] trim(Collection<T> col) {

    String[] result = new String[col.size()];

    int index = 0;
    for (T e : col) {
        result[index++] = e.toString().trim();
    }//from  w w w. jav  a 2 s  .c o m

    return result;

}

From source file:Main.java

public static short[] toShortArray(Collection<? extends Number> c) {
    short arr[] = new short[c.size()];
    int i = 0;//from   ww w  .  j  a v  a2  s . co  m
    for (Number item : c) {
        arr[i++] = item.shortValue();
    }
    return arr;
}

From source file:Main.java

public static boolean isEmpty(Collection c) {
    if (c != null) {
        if (c.size() > 0) {
            return false;
        } else {/*from ww  w  . j a v a2  s.c o  m*/
            return true;
        }
    } else {
        return true;
    }
}

From source file:Main.java

public static int clear(final Collection collection) {
    final int size = collection.size();
    collection.clear();//from w ww.  j  av  a 2s  .c  o m
    return size;
}

From source file:Main.java

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

From source file:Main.java

public static <T> String[] toStringArray(Collection<T> col) {

    String[] result = new String[col.size()];

    int index = 0;
    for (T e : col) {
        result[index++] = e.toString();/*from ww w .  ja  v a  2  s  .  c  om*/
    }

    return result;

}

From source file:Main.java

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