Should I Parallelize Java 8 Streams?

[Java] parallel streams

In Java 8, the streams API is easy to iterate over collections, and it's easy to parallelize a stream by calling the parallelStream() method. But should we be using parallelStream() wherever we can? What are the considerations? 

You may also like: Think Twice Before Using Java 8 Parallel Streams

Look at the following ParallelStreamTester class to generate collections of different sizes for the purpose of testing parallel streams performance against a sequential stream.  

Java Joy: Combining Predicates

Combining predicates in Java brings developers lots of joy.

In Java, we can use a Predicate to test if something is true or false. This is especially useful when we use the filter method of the Java Stream API.

You may also like: Towards More Functional Java Using Lambdas as Predicates

We can use lambda expressions to define our Predicate or implement the Predicate interface. If we want to combine different Predicate objects, we can use the or, and, and negate methods of the Predicate interfaces. These are default methods of the interface and will return a new Predicate.