June 10, 2016

Java Streams in Java 8

java.util.stream.Stream

Stream is a new feature in Java 8 that brings a lot of operation for Collections. Here I will present the most important, but for a complete list see the Java API.

In the below examples I will use a List of Strings.

filter()

map()

The map() method converts each element into another object via the given function.

sorted()

collect()

Creates a new Collection.

match()

Returns matched elements in Collections.

count()

reduce()

Collaps the entire Collections to single element.

No comments: