Monday, December 24, 2018

Java Streams

In Java-8, Streams can be obtained in a number of ways. Some examples are:

From a Collection via the stream() and parallelStream() methods.
From an array via Arrays.stream(Object[]).
From static factory methods on the stream classes, such as Stream.of(Object[]), IntStream.range(int, int) or Stream.iterate(Object, UnaryOperator).
The lines of a file can be obtained from BufferedReader.lines().
Streams of file paths can be obtained from methods in Files.
Streams of random numbers can be obtained from Random.ints().
Numerous other stream-bearing methods in the JDK, including BitSet.stream(), Pattern.splitAsStream(java.lang.CharSequence), and JarFile.stream().


Here is the list of all Stream intermediate operations:

filter()
map()
flatMap()
distinct()
sorted()
peek()
limit()
skip()

Here is the list of all Stream terminal operations:

toArray()
collect()
count()
reduce()
forEach()
forEachOrdered()
min()
max()
anyMatch()
allMatch()
noneMatch()
findAny()
findFirst()

No comments:

Post a Comment