February 2018
Intermediate to advanced
350 pages
7h 35m
English
The Collectors.toMap() function helps us repackage the Stream into Map implementation. This function offers a lot of customizations. The simplest version accepts two lambdas; the first one is to determine the key of Map Entry, and the second lambda is to determine the value of Map Entry. Please note, each element in the Stream will be represented in an entry in the Map.
Those two lambdas will get each element of the Stream in separate iterations and are expected to generate a key/value based on them.
Have a look at the following example:
fun main(args: Array<String>) { val resultantMap = (0..10).asSequence().asStream() .collect(Collectors.toMap<Int,Int,Int>({ it },{ it*it })) println("resultantMap ...Read now
Unlock full access