Is there any better way to find the duplicate words count in a file using Java. I have found one solution using Map like below :
while ((line = br.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, " ");
while (st.hasMoreTokens()) {
String tmp = st.nextToken().toLowerCase();
if (map.containsKey(tmp)) {
map.put(tmp, map.get(tmp) + 1);
} else {
map.put(tmp, 1);
}
}
}
Taken from OnlineTutorialsPoint
Looking for bettor logic interms of performance.