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

3

u/[deleted] Dec 12 '20

This book helped me a lot.

1

u/King5lay3r Dec 12 '20

Thanks for the suggestion fellow reader. Will surely have a look.

2

u/[deleted] Dec 12 '20

I always recommend that editorial. I haven't read anything that it's not good (and usually they are better than just good).

This particular book covers from the (not so) new functional interfaces (including default methods), to lambdas, method references and streams.

Note aside, I just read your username. Jaime?

1

u/King5lay3r Dec 12 '20

I just read your username. Jaime?

YEAH!

brb having a Season 8 PTSD attack