Check out example codes for "ArrayList Object[] toArray() method in java". It will help you in understanding the concepts better.

Code Example 1

import java.util.ArrayList;
import java.util.List;
public class ArrayListObjectToArrayMethodExample
{
   public static void main(String[] args)
   {
      List<Integer> al = new ArrayList<Integer>();
      al.add(12);
      al.add(14);
      al.add(16);
      al.add(18);
      al.add(20);
      Object[] obj = al.toArray();
      for(Object num : obj)
      {
         System.out.print(num + " ");
      }
   }
}

Code Example 2

// Java Program to illustrate the 
// ArrayList toArray(T[]) 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(T[]) method 
        Integer arr[] = new Integer[ArrLis.size()]; 
        arr = ArrLis.toArray(arr); 
  
        System.out.println("Elements of ArrayList"
                           + " as Array: "
                           + Arrays.toString(arr)); 
    } 
}

Code Example 3

// 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)); 
    } 
}

Learn ReactJs, React Native from akashmittal.com