answer action

Can’t find an answer?

Make use of a qualified tutor to get the answer

Toby Y.
333
Q:

Java : java array to list

Features

Java
Integer[] spam = new Integer[] { 1, 2, 3 };
List<Integer> list = Arrays.asList(spam);
9
List<Element> list = Arrays.asList(array);
4
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
List<String> list = new ArrayList<>();
list.add("a");
list.add("ab");
list.add("abc");
list.add("abcd");
// convert
String[] array = list.toArray();
5
/*
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
ArrayList<String> ArrayLister=new ArrayList<>(){ArrayLister.add("Hi")};
String[] array=ArrayLister.toArray(String[]);
2
// Java Program to illustrate the 
// ArrayList toArray() method in Java 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
  
        // create object of ArrayList 
        ArrayList<Integer> ArrLis 
            = new ArrayList<Integer>(); 
  
        // Add elements 
        ArrLis.add(32); 
        ArrLis.add(67); 
        ArrLis.add(98); 
        ArrLis.add(100); 
  
        // print ArrayList 
        System.out.println("ArrayList: "
                           + ArrLis); 
  
        // Get the array of the elements 
        // of the ArrayList 
        // using toArray() method 
        Object[] arr = ArrLis.toArray(); 
  
        System.out.println("Elements of ArrayList"
                           + " as Array: "
                           + Arrays.toString(arr)); 
    } 
} 
1
Your Answer

New to Communities?

Join the community