Danny  Han
0
Q:

convert array to list java

Integer[] spam = new Integer[] { 1, 2, 3 };
List<Integer> list = Arrays.asList(spam);
9
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()]; 
arr = al.toArray(arr); 
1
Integer[] arr = new Integer[al.size()]; 
  
        // ArrayList to Array Conversion 
        for (int i = 0; i < al.size(); i++) 
            arr[i] = al.get(i); 
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