Convert an ArrayList to an Array in Java



public class ConvertArrayList2Arrays {
   
  public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

   list.add("Blobbo");
 
    list.add("Cracked");

    list.add("Dumbo");
  // Now if you want to store the list in an array, you can do one of these
   Object[] arrOfObjects = new Object[]{list.size()};
// Convert list items in an Object type of array
   Object[] arrOfObjects = list.toArray();
// Convert list items in an Generic (String) type of array
  String[] arrayOfStrings = list.toArray(new String[list.size()]);
   }
}


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email