r/javahelp • u/King5lay3r • Dec 12 '20
How do I master Java Streams/Functional Programming?
I was asked to count occurrences of each characters in a String using Java 8 Stream API and although I know basic operations in Streams I would have never guessed the following Collectors.toMap() solution;
Collectors.toMap(k -> Character.valueOf((char) k.intValue()),
v -> 1,
Integer::sum)How, and from where, do I learn such declarative functional programming so that I can know when to use what by looking at the problem?
19
Upvotes
12
u/desrtfx Out of Coffee error - System halted Dec 12 '20 edited Dec 12 '20
Learning streams is a mix of googling (StackOverflow) and practice, practice, practice.
The Advent Of Code competition that is currently ongoing is an excellent playground to learn these.