java arraylist to array
// 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));
}
}
// A Java program to convert an ArrayList to arr[]
import java.io.*;
import java.util.List;
import java.util.ArrayList;
class GFG {
public static void main(String[] args)
{
List<Integer> al = new ArrayList<Integer>();
al.add(10);
al.add(20);
al.add(30);
al.add(40);
Integer[] arr = new Integer[al.size()];
arr = al.toArray(arr);
for (Integer x : arr)
System.out.print(x + " ");
}
}