Queuequeue = new LinkedList<>(); queue.add("apple"); queue.add("banana"); queue.add("cherry"); String[] arr = queue.toArray(new String[queue.size()]);
QueueThis example is similar to the previous one, but we create a queue of integers. We add three integers to the queue and then use the toArray() method to convert the queue into an array of integers. The resulting array contains the integers 1, 2, and 3 in the correct order. The java.util.Queue interface and the toArray() method are part of the Java Collections Framework.queue = new LinkedList<>(); queue.add(1); queue.add(2); queue.add(3); Integer[] arr = queue.toArray(new Integer[queue.size()]);