convert array list to array java code example

Example 1: convert list to array python

import numpy as np
my_list = [2,4,6,8,10]
my_array = np.array(my_list)
# printing my_array
print my_array
# printing the type of my_array
print type(my_array)

Example 2: java array to list

Integer[] spam = new Integer[] { 1, 2, 3 };
List<Integer> list = Arrays.asList(spam);

Example 3: java arraylist to array

List<String> list = new ArrayList<>();
list.add("a");
list.add("ab");
list.add("abc");
list.add("abcd");
// convert
String[] array = list.toArray();

Example 4: arraylist to array java

ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
String[] array=ArrayLister.toArray(String[]);

Example 5: convert list to array in java

Integer[] arr = new Integer[al.size()]; 
arr = al.toArray(arr);

Tags:

Java Example