Listlist = new ArrayList<>(); list.add("apple"); list.add("banana"); list.add("cherry"); String[] array = list.toArray(new String[list.size()]);
ListIn this example, we create a list of integers using a linked list implementation. We add three integers to the list, then convert the list to an array of integers using the toArray() method. The java.util package includes the List interface and associated classes, including ArrayList and LinkedList, that implement the list interface.list = new LinkedList<>(); list.add(1); list.add(2); list.add(3); Integer[] array = list.toArray(new Integer[list.size()]);