Friday, October 27, 2017

Java 8 Streams, Predicates and Lambdas

Eliminate for loops with streams and eliminate if conditionals with predicates and lambdas.

The example on line 63 is the most concise and modern example but, being concise, may not be the easiest to understand initially.

The legacy code example is the method on line 68.

The method on line 78 accepts a predicate but uses a for loop.

The method on line 88 accepts a predicate and uses the stream method instead of a for loop.