@keang: Yes, that is the best approach.

@joebar: Here is some working code

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class CountFrequency {

/**
* The purpose of this class is to find the frequency of each string in a text document. As of now, the text file is
* restricted to one line
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {

try {
FileReader fr = new FileReader("D:/textDoc.txt");
BufferedReader br = new BufferedReader(fr);
String[] line = br.readLine().split("[ ,\\.]");

/*
* Put string and frequency as key-value pairs in a hash map
*/
Map map = null;
for (String s : line) {
if (s != null && s.trim()!="") {
if (map == null) {
map = new HashMap();
map.put(s, 1);
} else {
int value = map.containsKey(s) ? ((Integer) map.get(s) + 1) : 1;
map.put(s, value);
}
}
}

Set set = map.keySet();
Iterator iter = set.iterator();
while (iter.hasNext()) {
String s = (String) iter.next();
System.out.println("String: " + s + "\t frequency: " + map.get(s));
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

}