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 short[] asShortArray(Collection<Short> collection) {
    short[] array = new short[collection.size()];
    Iterator<Short> iterator = collection.iterator();
    int i = 0;//from ww  w.  j  a  v  a2s  .  c o m
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}

From source file:Main.java

public static <T> boolean isEmpty(Collection<T> list) {

    if (list == null || list.isEmpty() || list.size() == 0) {
        return true;
    }//from w w  w.  j  a  v  a  2 s . com
    return false;
}

From source file:Main.java

/**
 * return collection size/*from w w w.  j  a va2 s .  c  o m*/
 *
 * @param collection <code>java.util.Collection</code>
 * @return size of collection
 */
public static int getCollectionSize(Collection collection) {
    return collection != null ? collection.size() : 0;
}

From source file:Main.java

public static boolean isNEmpty(Collection<?> collection) {
    if ((collection != null) && (collection.size() > 0)) {
        return true;
    }//from  www  . j a  v a2  s.co m
    return false;
}

From source file:Main.java

public static <T> boolean hasDuplicates(Collection<? extends T> xs) {
    HashSet<T> ys = new HashSet<>(xs.size());

    for (T x : xs)
        if (!ys.add(x))
            return true;

    return false;
}

From source file:Main.java

public static <T extends Object> void addAll(Collection<T> target, Collection<T> source) {
    if (target != null && source != null && source.size() > 0) {
        target.addAll(source);//from w w  w .j a v  a  2s. c o m
    }
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static char[] asCharArray(Collection<Character> collection) {
    char[] array = new char[collection.size()];
    Iterator<Character> iterator = collection.iterator();
    int i = 0;//from   ww w  .ja v a2s.  c  o  m
    while (iterator.hasNext()) {
        array[i++] = iterator.next();
    }
    return array;
}

From source file:Main.java

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