exo5: add a SortedMap from the TreeMap.
[Project_POO.git] / exo5 / Main.java
index 953bdfe46f61bf06b962e85745c9feeacae93d06..1ec751215c7c5bd4710ca47cefe6a69f39c6a297 100644 (file)
@@ -2,6 +2,7 @@ import java.io.File;
 import java.util.Scanner;
 import java.io.IOException;
 import java.util.TreeMap;
+import java.util.SortedMap;
 
 class Main {
 
@@ -10,6 +11,8 @@ class Main {
      * @param String[] args main() function arguments array
      */
     public static void main(String[] args) {
+        //TreeMap<String, Integer> tm = new TreeMap<String, Integer>(new StrComparator());
+        // default TreeMap comparator keep alphabetical order
         TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
         File f = new File("test_file.txt");
         try {
@@ -28,8 +31,16 @@ class Main {
         catch (IOException e) {
             e.printStackTrace();
         }
+
+        System.out.println("TreeMap full content:");
         for (String wordCursor : tm.keySet()) {
             System.out.println("Word \"" + wordCursor + "\" occured " + tm.get(wordCursor) + " times");
         }
+
+        System.out.println("SortedMap content after the word \"milieu\":");
+        SortedMap<String, Integer> stm = tm.tailMap("milieu");
+        for (String wordCursor : stm.keySet()) {
+            System.out.println("Word \"" + wordCursor + "\" occured " + stm.get(wordCursor) + " times");
+        }
     }
 }