- Read a line: Read String line by line in Java
- Split each line using a space character: Java split string to array
- The result of #2 will give you an array of String Objects.
-
Use the HashMap data structure (stores a key/value pair) to store each element:
HashMap hashMap = new HashMap(); hashMap.put(key, value); ie. hashMap.put(array[0], 0)
-
Iterate through the map each time you try to add an element. If the key exists, increment the value pair. Otherwise, put the new element in.
- Print the HashMap.
0
solved Print Number of occurences of each word in a File [closed]