Java Convert ArrayList to LinkedList

Tags: ArrayList LinkedList

In this Java core tutorial we learn how to convert a java.util.ArrayList to a java.util.LinkedList in Java programming language.

How to convert ArrayList to LinkedList in Java

In Java, with a given ArrayList object we can use the LinkedList(Collection<? extends E> c) constructor to create a new LinkedList object from the ArrayList elements.

In the following Java program we show how to use this ArrayList constructor to convert an ArrayList object to a ArrayList object.

ConvertArrayListToLinkedListExample1.java

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

public class ConvertArrayListToLinkedListExample1 {
    public static void main(String... args) {
        List<String> arrayList = new ArrayList<>();

        arrayList.add("Red");
        arrayList.add("Green");
        arrayList.add("Blue");

        LinkedList<String> linkedList = new LinkedList<>(arrayList);

        System.out.println("ArrayList: " + arrayList);
        System.out.println("LinkedList: " + linkedList);
    }
}
The output as below.
ArrayList: [Red, Green, Blue]
LinkedList: [Red, Green, Blue]

Happy Coding 😊

Java Convert ArrayList to Array

Java Convert ArrayList to String

Java Convert ArrayList to Comma Separated String

Java Convert ArrayList to HashSet

Convert Array to List in Java

Java Create New Array with Class Type and Length

Java Create ArrayList using List Interface

Java Get Index of Minimum Value in ArrayList

How to use Java ArrayList with Examples

Java Convert Array to ArrayList

Java Insert Element to ArrayList at Specified Index

Java Get Minimum Value in ArrayList

How to Traverse ArrayList using Iterator in Java

How to Traverse ArrayList using for each loop in Java

How to Traverse ArrayList using forEach() method in Java

Java Add Element to ArrayList