Java Utililty Methods Collection to Array

List of utility methods to do Collection to Array

Description

The list of methods to do Collection to Array are organized into topic(s).

Method

int[]toIntArray(Collection coll)
to Int Array
Iterator iter = coll.iterator();
int[] arr = new int[coll.size()];
int i = 0;
while (iter.hasNext()) {
    arr[i++] = (Integer) iter.next();
return arr;
int[]toIntArray(Collection coll)
convert the collection to int array.
if (coll == null || coll.isEmpty()) {
    return null;
final int[] arr = new int[coll.size()];
final Iterator<Integer> it = coll.iterator();
int i = 0;
for (; it.hasNext();) {
    arr[i++] = it.next();
...
int[]toIntArray(Collection collection)
to Int Array
if (collection == null)
    throw new RuntimeException("Can't do toIntArray. Collection is Null");
int[] result = new int[collection.size()];
int i = 0;
for (Integer el : collection)
    result[i++] = el;
return result;
Integer[]toIntArray(Collection collection)
Copy the given Collection into a String array.
if (collection == null) {
    return null;
return (Integer[]) collection.toArray(new Integer[collection.size()]);
int[]toIntArray(Collection collection)
to Int Array
int[] newArray = new int[collection.size()];
if (collection instanceof List) {
    List<Integer> list = (List<Integer>) collection;
    for (int i = 0; i < list.size(); i++) {
        Integer value = list.get(i);
        newArray[i] = value.intValue();
} else {
...
int[]toIntArray(Collection collection)
Returns an array of ints consisting of the elements of the specified collection.
int array[] = new int[collection.size()];
int index = 0;
Iterator<Integer> it = collection.iterator();
while (it.hasNext()) {
    array[index++] = it.next();
return array;
int[]toIntArray(Collection ints)
Converts any collection of Integer into an int array.
int[] out = new int[ints.size()];
int i = 0;
for (Integer boxed : ints) {
    out[i++] = boxed.intValue();
return out;
int[]toIntArray(Collection list)
to Int Array
int n = list == null ? 0 : list.size();
int[] arr = new int[n];
if (list != null) {
    int i = 0;
    for (int d : list)
        arr[i++] = d;
return arr;
...
int[]toIntArray(Collection list)
to Int Array
if (list == null || list.isEmpty()) {
    return EMPTY_INT_ARRAY;
int[] result = new int[list.size()];
int i = 0;
for (Integer integer : list) {
    result[i++] = integer;
return result;
int[]toIntArray(Collection values)
to Int Array
int[] result = new int[values.size()];
int i = 0;
for (int value : values)
    result[i++] = value;
return result;