Also read : Convert ArrayList in Streams in java 8
Circuiting Operations in Streams in java 8
Convert ArrayList of Integers to Streams in java 8
1) Program/ Example - Convert ArrayList of String to Streams in java 8
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
/**
* Write Program to - Convert ArrayList of String to Streams - in java 8
*/
public class ConvertArrayListOfStringToStreamsExample {
public static void main(String[] args) {
System.out.println("1. Create list of String");
List<String> listOfStrings = new ArrayList<>();
listOfStrings.add("a");
listOfStrings.add("b");
System.out.println("2. Convert list (ArrayList) of String to stream");
Stream<String> streamOfString = listOfStrings.stream();
System.out.println("3. Display Stream of String");
streamOfString.forEach(System.out::println);
}
}
/* OUTPUT
1. Create list of String
2. Convert list (ArrayList) of String to stream
3. Display Stream of String
a
b
*/
|
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.