Thursday, 30 June 2016

How to convert List to Stream in Java 8

Convert a java.util.List to java.util.Stream in Java 8

In my previous example I showed "How to convert Stream into a List in Java 8".
In this example I will show how to convert a List into a Stream in Java 8.

Collections like the List can be easily obtained from a Java 8 Stream
by calling the stream() operation over a List.
This is a inbuilt feature and it helps in easy conversions from collections to Stream data.

List<String> itemList=Arrays.asList("List","to","Stream","Java8","Stream");

//Converting List to Stream in Java 8

itemStream.distinct().forEach(x -> System.out.print(x+" "));

SEE ALSO: How to convert Stream into a List in Java 8

No comments:

Post a Comment

Coder Magnet
CoderMagnet is full of resources from our daily development activities. It has solutions for common problematic scenarios in technologies like Java 8, AEM, JCR and also occasionally gives you tips on Blogger as well.