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

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

From source file:Main.java

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

From source file:Main.java

public static boolean isPresent(Collection<? extends Object> objects) {
    return ((objects != null) && (objects.size() > 0));
}

From source file:Main.java

/**
 * Return true if <tt>a</tt> contains at least one element
 * which is not contained in <COCE>b</tt>
 *
 * @param a <tt>Collection</tt> to be examined.
 * @param b <tt>Collection</tt> to be refered to
 *
 * @return true if <tt>s</tt> contains at least one elment which is
 * not contained in <tt>b</tt>
 *///  w ww. ja  va2  s. c om
public static boolean hasOtherThan(Collection<?> a, Collection<?> b) {
    if (a.size() > b.size())
        return true;

    return !b.containsAll(a);
}

From source file:Main.java

public static <T> T random(Collection<T> coll) {
    int num = (new Random().nextInt(coll.size()));
    for (T t : coll) {
        if (--num < 0) {
            return t;
        }// w  w  w  .ja v a2  s  .  c  o  m
    }

    return null;
}

From source file:Main.java

public static int[] asIntArray(Collection<Integer> collection) {
    int[] array = new int[collection.size()];
    Iterator<Integer> iterator = collection.iterator();
    int i = 0;//from   ww w  . j  a  v  a  2  s  . c om
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static double[] toDoubleArray(Collection<? extends Number> c) {
    double arr[] = new double[c.size()];
    int i = 0;/*from   w ww  .  j  a  v a  2 s  .  c o m*/
    for (Number item : c) {
        arr[i++] = item.doubleValue();
    }
    return arr;
}