Java Utililty Methods List to Array

List of utility methods to do List to Array

Description

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

Method

String[][]ListToArray(List> values)
List To Array
String[][] results = new String[values.size()][2];
int index = 0;
for (List<String> value : values) {
    results[index][0] = value.get(0);
    results[index][1] = value.get(1);
    index++;
return results;
...
String[]listToArray(List list)
list To Array
String[] a = new String[0];
return (String[]) list.toArray(a);
String[]listToArray(List stringList)
Retrieves a string array containing the contents of the provided list of strings.
if (stringList == null) {
    return null;
String[] stringArray = new String[stringList.size()];
stringList.toArray(stringArray);
return stringArray;
T[]listToArray(List list)
list To Array
@SuppressWarnings("unchecked")
T[] array = (T[]) new Object[list.size()];
for (int i = 0; i < list.size(); i++) {
    T f = list.get(i);
    array[i] = (f != null ? f : null); 
return array;
String[]toArray(Collection list)
Converts a collection ( List , Set ...) of objects to a String array.
if (list == null)
    return new String[0];
String[] out = new String[list.size()];
int i = 0;
Iterator it = list.iterator();
while (it.hasNext())
    out[i++] = it.next().toString();
return out;
...
double[]toArray(Collection list)
Converts a collection ( List , Set ...) of Double objects to a double array.
return asPrimitiveArray(list.toArray(new Double[list.size()]));
double[]toArray(final List list)
to Array
final double array[] = new double[list.size()];
for (int i = 0; i < array.length; i++) {
    array[i] = list.get(i).doubleValue();
return array;
int[]toArray(final List list)
to Array
final int n = list.size();
final int[] array = new int[n];
for (int i = 0; i < n; ++i) {
    array[i] = list.get(i);
return array;
int[]toArray(final List list)
Returns an int array created using Integer list.
final int[] array = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
    final Integer integer = list.get(i);
    array[i] = integer != null ? integer : 0;
return array;
String[]toArray(List list)
to Array
return (String[]) list.toArray(new String[list.size()]);