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

Class[]toClassArray(Collection> collection)
to Class Array
return collection == null ? null : collection.toArray(new Class[collection.size()]);
Class[]toClassArray(final Collection collection)
Convert the collection of class types to an array of class types.
return (Class[]) collection.toArray(new Class[collection.size()]);
Double[]toDouble(final Collection numbers)
to Double
return toDouble(numbers.toArray(new Number[numbers.size()]));
double[]toDoubleArray(Collection items)
Convert a Collection of Numbers to an array of primitive doubles Null values will be skipped in the array
double ret[] = new double[items.size()];
int idx = 0;
for (Number n : items) {
    if (n != null)
        ret[idx] = n.doubleValue();
    idx += 1;
return (ret);
...
double[]toDoubleArray(Collection ds)
to Double Array
double[] out = new double[ds.size()];
int index = 0;
for (Double d : ds)
    out[index++] = d;
return out;
Double[]toDoubleArray(final Collection doubleColl)
Converts the given collection of Doubles to an array of Doubles.
if (doubleColl == null) {
    return new Double[0];
return doubleColl.toArray(new Double[doubleColl.size()]);
ObjecttoFloatArray(Collection collection)
to Float Array
return toFloatArray(new float[collection.size()], collection);
float[]toFloatArray(Collection c)
to Float Array
float arr[] = new float[c.size()];
int i = 0;
for (Number item : c) {
    arr[i++] = item.floatValue();
return arr;
float[]toFloatArray(Collection array)
to Float Array
float[] resultArray = new float[array.size()];
int i = 0;
for (float s : array) {
    resultArray[i++] = s;
return resultArray;
float[]toFloatArray(final Collection c)
to Float Array
if (null == c || c.isEmpty()) {
    return new float[0];
final float[] list = new float[c.size()];
int i = 0;
for (final Number item : c) {
    list[i] = item.floatValue();
    i++;
...