We want to prototype in Node.js a stream processing program that will eventually be coded in Java 8+.
Node.js Collections Processing with Lodash
So mapping a collection, squaring each element, we use an arrow function to process each element:
var _ = require(‘lodash’);
_.map([1, 2, 3, 4], (a) => a * a)
Java 8 Streams
Java 8 streams represents a sequence of elements and supports different kind of operations to perform computations upon those elements:
List<Integer> myList =
Arrays.asList(1, 2, 3, 4);
.map((a) -> a * a)
The notation of the processing is like the Node.js code above which used arrow functions and Lodash.
Convert the Node.js into Java
Very simple! The arrow notation stays the same, most of the functions have the same name. Just copy-paste and spread type declarations around the original Node.js variables.