Skip to content

Convert LinkedHashSet to ArrayList in Java Example

This example shows how to convert LinkedHashSet to ArrayList in Java. This example also shows how to convert LinkedHashSet to ArrayList using constructor, Java 8 Stream, and addAll method.

How to convert LinkedHashSet to ArrayList in Java?

There are several using which we can convert LinkedHashSet to an ArrayList in Java as given below.

1. Using ArrayList constructor

The ArrayList class provides a constructor that accepts a collection object.

It creates a new ArrayList object containing all elements of the specified collection object.

Output

2. Using the addAll method of the ArrayList class

We can also create an empty ArrayList object and then we can add all elements of the LinkedHashSet object using the addAll method of the ArrayList class.

Output

3. Using Apache Commons CollectionUtils class

If you are using the Apache Commons library in your project, you can use the addAll method of the CollectionUtils class to add all elements of the LinkedHashSet object to an empty ArrayList object as given below.

Output

4. Using Java 8 stream

If you are using Java version 8 or later, you can use the Java stream to convert the Set to a List as given below.

Output

This example is a part of the LinkedHashSet in Java Tutorial with Examples.

Please let me know your views in the comments section below.

References:
Java 8 LinkedHashSet

About the author

Leave a Reply

Your email address will not be published.