Hi folks, In this blog we would talk about one of the features of Java 8 which is Streams. The java package java.util.stream contains classes to support functional-style operations on streams i.e. map, filter etc. Streams is not a data structure that stores something instead of it a way to flow data from source to destination with some intermediate operation in between. Let’s take an example first so that we can grasp concepts fast.
Let’s say, we have a collection of books Collection where Book class has two attributes writer and price and we want to obtain the sum of price’s where the writer is “Neil Chetan”. In order to obtain the result, we need to do some like –
int totalPrice = collection.stream()
.filter(b -> b.getWriter() == "Neil chetan")
.map(b -> b.getPrice())
.sum();
The stream is a series of operations that can be Intermediate or terminal operation.
#java #scala #tech blogs #java 8 streams #java8 #streams