Java Collection to List

Previous
Next

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.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog