Posts

Showing posts with the label New collectors - filtering and flatMapping

Java 9 - Stream API improvements

Image
Hi, I am Malathi Boggavarapu working at Volvo Group and i live in Gothenburg, Sweden. I have been working on Java since several years and had vast experience and knowledge across various technologies. Stream API improvements Now we learn about Stream API improvements done in java 9. Let's start with the example class Book. It have fields title, authors and price. And we also have methods getBook and getBooks. As their name indicates, getBook method returns a book and getBooks returns list of books. Stream.ofNullable Now we illustrate Stream.ofNullable method. If we see the below code, when we pass null to the ofNullable method of Stream and call count method on it, it returns zero. And when we call getBook method inside ofNullable method, stream returns the count as one. Try the example!! We are going to look at one more example which is more involved. It illustrates the difference in code before and after java 9 - ofNullable ...