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 boolean isNotEmpty(Collection<?> col) {
    return col != null && col.size() > 0;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isBlank(Collection c) {
    return c == null || c.size() == 0;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isNotBlank(Collection c) {
    return c != null && c.size() > 0;
}

From source file:Main.java

public static double average(Collection<Double> arr) {
    if (arr.size() > 0) {
        return sum(arr) / arr.size();
    } else {//from  w w w .  j  a v  a 2s .  c o  m
        return 0;
    }
}

From source file:Main.java

public static boolean isEmpty(Collection<?> objs) {
    if (objs == null || objs.size() <= 0) {
        return true;
    }/*from  w  w  w  .j a  va2 s  .c  o m*/
    return false;
}

From source file:Main.java

public static <T> T getSingle(Collection<T> configs) {
    if (configs.size() == 1) {
        for (T t : configs) {
            return t;
        }//from   www  .ja  v a 2s  . c o m
    }
    return null;
}

From source file:Main.java

/**
 *  Returns <code>true</code> if the passed collection is not <code>null</code>
 *  and has size &gt; 0.//  w ww  .j  a v a2 s  .co m
 */
public static boolean isNotEmpty(Collection<?> c) {
    return (c != null) && (c.size() > 0);
}

From source file:Main.java

public static boolean intersect(Collection<?> a, Collection<?> b) {
    if (b.size() > a.size()) {
        Collection<?> c = a;
        a = b;/* ww  w  . j av a2  s  .  c o  m*/
        b = c;
    }
    return intersect(a, (Iterable<?>) b);
}

From source file:Main.java

/**
 * Return the first item from a collection using the most efficient
 * method possible. Returns null for an empty collection.
 *
 * @param c The Collection./*w w w  .  j a  v a2s  . c  o m*/
 * @return the first element of a Collection.
 */
public static Object getFirstItemOrNull(Collection c) {
    if (c.size() == 0) {
        return null;
    }
    return getFirstItem(c);
}

From source file:Main.java

/**
 * @param c/*from   ww w .j  a va 2  s  .  com*/
 * @return size of {@link c} if c is not {@code null}, 0 otherwise
 */
public static int size(Collection<?> c) {
    return c != null ? c.size() : 0;
}