List of utility methods to do Collection to Array
Object[] | asArray(Collection c) Returns an array with the elements in a given collection. Object[] array = new Object[c.size()]; int i = 0; for (Iterator it = c.iterator(); it.hasNext();) { array[i++] = it.next(); return array; |
E[] | asArray(Collection collection, E[] a) as Array return asList(collection).toArray(a);
|
boolean[] | asBooleanArray(Collection as Boolean Array boolean[] array = new boolean[collection.size()]; Iterator<Boolean> iterator = collection.iterator(); int i = 0; while (iterator.hasNext()) { array[i++] = iterator.next(); return array; |
long[] | asLongArray(final Collection extends Number> ls) as Long Array final long[] d = new long[ls.size()]; int i = 0; for (final Number num : ls) d[i++] = num.longValue(); return d; |
long[] | asLongArray(java.util.Collection extends Number> c) Returns 'c' as a long array. int i = 0, n = (c == null) ? 0 : c.size(); long[] ans = new long[n]; if (n > 0) for (Number nr : c) ans[i++] = nr.longValue(); return ans; |
Object[] | collectionToArray(Collection collection) collection To Array Object[] objs = null; if (isNotEmpty(collection)) { objs = new Object[collection.size()]; collection.toArray(objs); return objs; |
int[] | collectionToIntArray(Collection collection To Int Array int[] toReturn = new int[c.size()]; Iterator<Integer> it = c.iterator(); for (int i = 0; i < toReturn.length; i++) { toReturn[i] = it.next().intValue(); return toReturn; |
int[] | collectionToIntArray(final Collection extends Number> numbers) collection To Int Array final int[] ret = new int[numbers.size()]; int i = 0; for (Number n : numbers) { ret[i++] = n.intValue(); return ret; |
Object[] | collectionToObjectArray(Collection c) Convenience method for converting a collection to an Object[] if (c == null) return new Object[0]; return c.toArray(new Object[c.size()]); |
CharSequence | collectionToObjectArray(final Collection collection To Object Array final StringBuilder ret = new StringBuilder(); if (!_list.isEmpty()) { boolean first = true; ret.append("["); for (final CharSequence entry : _list) { if (first) { first = false; } else { ... |