[Solved] Print Number of occurences of each word in a File [closed]


  1. Read a line: Read String line by line in Java
  2. Split each line using a space character: Java split string to array
  3. The result of #2 will give you an array of String Objects.
  4. 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)
    
  5. 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.

  6. Print the HashMap.

0

solved Print Number of occurences of each word in a File [closed]