Java Collection to List

In this post, we will see how to convert Java Collection to List.

There are many ways to do it, we will see two ways here.


Using ArrayList constructor

Above ArrayList‘s constructor creates a list having the elements of the specified collection, in the order they are returned by the collection’s iterator.


Using Java 8 Stream

You can use Java 8‘s stream as well to convert any collection to the List.

Complete program for converting  Java Collection to List.

When you run above program, you will get below output

Set Elements:
[John, Martin, Mary] List elements:
[John, Martin, Mary] ===================
Values of Map are:
[32, 18, 23, 34] ===================
Using Java 8
List elements:
[John, Martin, Mary] Values of Map are:
[32, 18, 23, 34]

That’s all about Java collection to List.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *