How do I convert LinkedList to array?

package org.kodejava.example.util;

import java.util.LinkedList;
import java.util.List;

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

        // Converting LinkedList to array can be done by calling the toArray()
        // method of the List;
        String[] colors = new String[list.size()];

        for (String color : colors) {
            System.out.println("color = " + color);

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. If these posts help, you can support me, buy me a cup coffee or tea. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.