Alice
20
Q:

convert java list to array

String[] arr = list.toArray(new String[list.size()]);
4
Integer[] array = new Integer[] {
  23, 54, 12
};

java.util.List<Integer> list = java.util.Arrays.asList(array);
System.out.println(list);
1
/*
Get the Array to be converted.
Create the List by passing the Array as parameter in the constructor of the List with the help of Arrays. asList() method.
Return the formed List.
*/

String[] namedata = { "ram", "shyam", "balram" }; 

List<String> list = Arrays.asList(namedata);
3
Arrays.asList(array);
3
Integer[] arr = new Integer[al.size()]; 
  
        // ArrayList to Array Conversion 
        for (int i = 0; i < al.size(); i++) 
            arr[i] = al.get(i); 
0
List<String> stockList = new ArrayList<String>();
stockList.add("stock1");
stockList.add("stock2");

String[] stockArr = new String[stockList.size()];
stockArr = stockList.toArray(stockArr);

for(String s : stockArr)
    System.out.println(s);
0
Collections.addAll(list, array);
0
Integer[] arr = new Integer[al.size()]; 
for (int i = 0; i < al.size(); i++) 
     arr[i] = al.get(i); 
0
// Java program to convert a List to an array 
// using toArray() in a loop. 
import java.util.*; 
  
public class GeeksforGeeks { 
    public static void main(String[] args) 
    { 
        List<String> list = new LinkedList<String>(); 
        list.add("Geeks"); 
        list.add("for"); 
        list.add("Geeks"); 
        list.add("Practice"); 
  
        String[] arr = list.toArray(new String[0]); 
  
        for (String x : arr) 
            System.out.print(x + " "); 
    } 
} 
0

New to Communities?

Join the community