Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

In this page you can find the example usage for java.util Collection isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:Main.java

/**
 * @return  True if the input collection is null of empty
 */// w  ww.j a  v a 2  s .com
public static boolean isNullOrEmpty(@Nullable Collection c) {
    return c == null || c.isEmpty();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static Long[] collectionToArray(Collection<String> collection) {
    if (collection == null || collection.isEmpty()) {
        return null;
    }// www  .j  a v  a  2  s . c  o  m
    Long[] arry = new Long[collection.size()];
    int index = 0;
    for (String value : collection) {
        arry[index++] = Long.valueOf(value);
    }
    return arry;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isEmpty(Collection collection) {
    return collection == null || collection.isEmpty();
}

From source file:Main.java

/**
 * @param nums Any descendant of Number (Integer, Short, Double, Float, etc)
 * @return The mean of the number, or Double.NaN if the list is empty.
 *//*from www  .  ja  va  2  s  .co m*/
public static double mean(Collection<? extends Number> nums) {
    if (nums == null || nums.isEmpty()) {
        return Double.NaN;
    }
    double sum = 0.0;
    for (Number n : nums) {
        sum += n.doubleValue();
    }
    return sum / nums.size();
}

From source file:Main.java

public static boolean isNotEmpty(Collection<? extends Object> list) {
    return (list != null) && (!list.isEmpty());
}

From source file:Main.java

public static <O> O getRandom(final Collection<O> pObjects) {
    if (pObjects != null && !pObjects.isEmpty()) {
        int r = Math.abs(random.nextInt() % pObjects.size());
        List<O> objects = !(pObjects instanceof List) ? new ArrayList<O>(pObjects) : (List<O>) pObjects;

        return objects.get(r);
    }/*from  w w  w  .  j a  va  2  s.  c o m*/
    return null;
}

From source file:Main.java

public static boolean isEmpty(Collection collection) {
    return (collection == null || collection.isEmpty());
}