r/javahelp • • 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 comments sorted by

View all comments

2

u/MRH2 Intermediate Brewer Dec 12 '20

That's a great question. I have no idea either.