$ 0 0 Following code snippet shows how you can write a word count program using Java 8 Stream API. The better solution is using toMap collector as shown below. Even better version can be written using grouping and counting collector as shown below.