Skip to content
Advertisement

Counting words using parallel Java arrays

I am trying to write code to count the frequency of each word in an array. I am wondering if I need to use two nested loops to keep track of both the array with integers and the array with the words. I have been fiddling with the code for hours and cannot make any progress. If you have any pointers, they would be much appreciated. I am given the input as first the number of elements in the array, then the words that I am supposed to count the frequency of, such as 4 dog cat dog fish.

JavaScript

Advertisement

Answer

Can you please try below solution?:

JavaScript

Using Java 8 Streams:

JavaScript

If your input is:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement