953bdfe46f61bf06b962e85745c9feeacae93d06
2 import java
.util
.Scanner
;
3 import java
.io
.IOException
;
4 import java
.util
.TreeMap
;
10 * @param String[] args main() function arguments array
12 public static void main(String
[] args
) {
13 TreeMap
<String
, Integer
> tm
= new TreeMap
<String
, Integer
>();
14 File f
= new File("test_file.txt");
16 Scanner sc
= new Scanner(f
);
17 while (sc
.hasNext()) {
18 String wordCursor
= sc
.next();
19 //NOTE: words comparaison is case sensitive and punctuation aware
20 Integer count
= tm
.get(wordCursor
);
24 tm
.put(wordCursor
, count
+ 1);
28 catch (IOException e
) {
31 for (String wordCursor
: tm
.keySet()) {
32 System
.out
.println("Word \"" + wordCursor
+ "\" occured " + tm
.get(wordCursor
) + " times");