Simple word count program using Java 8 – Imperative vs Functional approach

Here’s a simple example to count the word occurrences in a given string. This presents two approaches. One is a classic imperative approach of iterating through words and keeping track of occurrences in a Map. Another is a functional approach using Java 8 streams.

Here’s the output:

Java 8 Streams Cheatsheet
Java 8 Streams Cheatsheet (Courtesy: JRebel)

Copy Protected by Chetan's WP-Copyprotect.