List of usage examples for java.util Collection size
int size();
From source file:Main.java
/** * @return size of collection if not null, otherwise 0. *///from ww w.ja v a 2 s .co m public static int size(final Collection<?> col) { return col != null ? col.size() : 0; }
From source file:Main.java
/** * Returns the size of the collection. If the collection is null, 0 will be returned. */// ww w .j av a2 s . co m public static int getSize(Collection<?> collection) { return collection != null ? collection.size() : 0; }
From source file:Main.java
public static boolean isEmpty(Collection<?> collection) { if (null == collection || collection.isEmpty() || collection.size() <= 0) return true; return false; }
From source file:Main.java
/** * Checks if the given array is null or its length is empty * //from w ww. j a v a2 s.c o m * @param collection * @return */ public static boolean isEmpty(Collection collection) { if (collection == null) return true; if (collection.size() == 0) return true; return false; }
From source file:Main.java
/** * Convert a Collection of Numbers to an array of primitive longs * Null values will be skipped in the array * @param items/*w w w .j a v a 2s.c o m*/ * @return */ public static long[] toLongArray(Collection<? extends Number> items) { long ret[] = new long[items.size()]; int idx = 0; for (Number n : items) { if (n != null) ret[idx] = n.longValue(); idx += 1; } // FOR return (ret); }
From source file:Main.java
/** * Returns the size of the specified collection. If the specified collection is null, this method returns the specified default size. * * @param c Collection of Objects referencing the collection to retrieve the size from. * @param defaultSize int referencing the size to be returned when the collection is null. * @return int referencing the size of the collection, or the default size when the collection is null. *//*from w w w . ja va 2s.com*/ public static int defaultSizeIfNull(Collection c, int defaultSize) { return (c == null ? defaultSize : c.size()); }
From source file:Main.java
/** * Creates a new {@link ArrayList} with the inferred type * using the given elements./* w w w. j a va2 s. com*/ */ public static <T> ArrayList<T> alist(Collection<T> vals) { ArrayList<T> ret = new ArrayList<T>(vals.size()); for (T v : vals) ret.add(v); return ret; }
From source file:Main.java
public static int size(Collection<?>... collections) { int size = 0; if (collections != null) { for (Collection<?> c : collections) { if (c != null) { size += c.size(); }/* ww w. ja va 2 s . c om*/ } } return size; }
From source file:Main.java
/** * Converts a collection into an array./*from www.j a v a2 s . co m*/ * @param collection the collection to convert * @param clazz the class of the items in the collections * @return a non-null array */ public static <T> T[] convertToArray(Collection<T> collection, Class<T> clazz) { T[] result = (T[]) Array.newInstance(clazz, collection.size()); return collection.toArray(result); }
From source file:Main.java
public static int size(Collection collection) { if (isEmpty(collection)) { return 0; }/*from w w w . j ava 2 s . c om*/ return collection.size(); }