Java 8 Stream (java.util.stream)
Java 8 Stream (java.util.stream)
Stream :
A stream is not a data structure; it takes input from
underlying Collections, Arrays or any other objects. Stream work on underlying object
and don’t change the original object. There are various intermediate operations
on stream which returns a stream again. There is also terminal operation which
terminates the process and collect the result.
In a nut shell stream is wrapper around underlying data
which has multiple operation to allow process the bulk data operation easily.
Create stream;
1. We can create stream using collection.
Stream strm = listObject.stream();
2. Using array Object
Stream strm = Stream.of(array);
3. Using any String or Integer value.
Stream<Integer> strm = Stream.of(1,3,4,6,4);
4. We can create empty stream
Stream<String> emptyStream = Stream.empty();
5. Using Stream builder
Stream builder= Stream.builder();
Stream<String> strm = builder.add("A").build();
Intermediate operations
Terminal operation
Labels: collect, filter, flatmap, forEach, intermediate operation terminal operation, Java 8 stream, java.util.stream, map, reduce
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home