I am in a search of a better performant algorithm to implement a program, to find the count of each word in a sentence i.e.., a String in the programming sense.
I know my algorithm is too basic and Noob. Here's my algorithm.
- Read the String.
- Tokenize the String with the delimiter, put each token in a list(ArrayList).
- Iterate the generated list, in each iteration compare the current string with every other string of the list, if it matches increase the count of this string.
- For each iteration, put the String and its count in a map.
- Iterate the map and display, with key as string and value as its count.
What is the best approach than this?