Stream generation process

Stream API introduced from Java 8 There are many convenient processes for operating Collection (Although it will be even more now) I will list it like a memo.

What is Stream API? Recognize that Stream itself is not a Collection element such as List or Map, but a pipeline for adding generation processing, intermediate processing, and termination processing to elements such as arrays and lists and replacing them with new elements.

Stream#of

Stream<String> stream = Stream.of("a","b","c");

Collection#stream

Generate from List

List<String> list = Arrays.asList("a","b","c");
Stream<String> stream = list.stream();

Generated from Map

Map<String,String> map = new HashMap<>();
Stream<Entry<String,String>> stream = map.entrySet().stream();

Arrays#Stream

String[] array = {"a","b","c"};
Stream<String> stream = Arrays.stream(array);

BufferedReader#lines

BufferedReader reader = new BufferedReader(newInputStreamReader(System.in, directory));
Stream<String> reader.lines();   

Recommended Posts

Stream generation process
Stream play
Stream termination
Memo Stream