This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Functional Programming!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Sometimes you will end up with a stream that returns a stream, flatMap helps you flatten your elements into a single stream.
Imperative Word Cloud Code
public static Map<String, Long> getSnippetWordCountsImperatively(List<Job> jobs) {
Map<String, Long> wordCounts = new HashMap<>();
for (Job job : jobs) {
String[] words = job.getSnippet().split("\\W+");
for (String word : words) {
if (word.length() == 0) {
continue;
}
String lWord = word.toLowerCase();
Long count = wordCounts.get(lWord);
if (count == null) {
count = 0L;
}
wordCounts.put(lWord, ++count);
}
}
return wordCounts;
}
Learn more
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
hamsternation
26,617 Points0 Answers
-
Edward Strudwick
2,036 Points2 Answers
-
Neil Brown
22,514 Points1 Answer
-
PLUS
Siu KWAN Yuen
Courses Plus Student 2,898 Points2 Answers
-
Andrey Serebryanskiy
5,756 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up