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

Double[]toArray(List values)
to Array
return values.toArray(new Double[values.size()]);
String[]toArray(List enums)
Converts a list of enumerations to an array of their Enum#toString() representation
String[] out = new String[enums.size()];
for (int i = 0; i < out.length; i++) {
    out[i] = enums.get(i).toString();
return out;
int[]toArray(List from, int[] to)
Copy the given List to the specified Array at offset zero.
if (to == null || to.length < from.size()) {
    to = new int[from.size()];
int i = 0;
for (Integer element : from) {
    to[i++] = element;
return to;
...
int[]toArray(List l)
Returns the non-null integers in the given list as an array.
if (l == null) {
    return null;
int count = 0;
for (Integer e : l) {
    if (e != null) {
        count++;
int[] result = new int[count];
int i = 0;
for (Integer e : l) {
    if (e != null) {
        result[i++] = e;
return result;
int[]toArray(List list)
to Array
int[] ret = new int[list.size()];
int i = 0;
for (Integer e : list) {
    ret[i++] = e.intValue();
return ret;
int[]toArray(List list)
Converts a list of integers to an array
int[] array = new int[list.size()];
for (int i = 0, l = list.size(); i < l; i++)
    array[i] = list.get(i);
return array;
int[]toArray(List list)
to Array
int[] result = new int[list.size()];
int index = 0;
for (Integer number : list) {
    result[index++] = number;
return result;
ListtoLongList(String str, String splitStr)
to Long List
if (str != null) {
    ArrayList<Long> longList = new ArrayList<Long>();
    String[] strList = str.split(splitStr);
    for (String string : strList) {
        longList.add(Long.parseLong(string));
    return longList;
return null;
ListtoLongList(String[] array)
Converts a String array to a long array.
List<Long> out = new ArrayList<Long>(array.length);
for (int i = 0; i < array.length; i++) {
    if (array[i] == null)
        throw new RuntimeException("Null value in position " + i);
    out.add(Long.parseLong(array[i]));
return out;
Object[]toObjectArray(List> lists)
to Object Array
List<String[]> output = new ArrayList<>();
for (List<String> l : lists) {
    output.add(l.toArray(new String[0]));
return output.toArray();