title: How do you sort a Map by its String Keys using comparator interface
body: <p>I know similar questions have been asked before but I have a specific problem which I can't get my head wrong.</p>
  
  <p>I want to sort a map by days of the week where days of the week are keys of the map. How do you compare strings which don't have natural order in compare method? Map at the end of the sort should be: Mon, Tue, Wed, Thur.</p>
  
  <p>Here is my code so far but I am stuck at compare method.</p>
  
  <pre><code>    class OpeningTimes {
  
         private String openingTime;
         private String closingTime;
         public String getOpeningTime() {
             return openingTime;
         }
         public void setOpeningTime(String openingTime) {
             this.openingTime = openingTime;
         }
         public String getClosingTime() {
             return closingTime;
         }
         public void setClosingTime(String closingTime) {
             this.closingTime = closingTime;
         }
  
         @Override
         public String toString() {
             return new StringBuilder( "Opening Times: " + this.openingTime + " Closing Times: " + this.closingTime).toString();
         }
     }
  </code></pre>
  
  <p>Comparator:</p>
  
  <pre><code>class OpeningTimesComparator implements Comparator&lt;Map.Entry&lt;String, OpeningTimes&gt;&gt;{
  
     @Override
     public int compare(Entry&lt;String, OpeningTimes&gt; o1, Entry&lt;String, OpeningTimes&gt; o2) {
         return 0; // what is the logic?
     }}
  </code></pre>
  
  <p>Runner:</p>
  
  <pre><code>public class TestClass {
  
      public static void main(String[] args) {
  
          Map&lt;String, OpeningTimes&gt; openingTimesMap = new TreeMap&lt;String, OpeningTimes&gt;();
  
          OpeningTimes openTime1 = new OpeningTimes();
          openTime1.setOpeningTime("9PM");
          openTime1.setClosingTime("10PM");
  
          OpeningTimes openTime2 = new OpeningTimes();
          openTime2.setOpeningTime("11PM");
          openTime2.setClosingTime("9PM");
  
          OpeningTimes openTime3 = new OpeningTimes();
          openTime3.setOpeningTime("13PM");
          openTime3.setClosingTime("14PM");
  
          OpeningTimes openTime4 = new OpeningTimes();
          openTime4.setOpeningTime("15PM");
          openTime4.setClosingTime("13PM");
  
          openingTimesMap.put("Tue", openTime2);
          openingTimesMap.put("Thu", openTime4);
          openingTimesMap.put("Mon", openTime1);
          openingTimesMap.put("Wed", openTime3);
  
  
          for (Entry&lt;String, OpeningTimes&gt; openingTimesSingle : openingTimesMap.entrySet()) {
              System.out.println("Key: " + openingTimesSingle.getKey() + " Value: " + openingTimesMap.get(openingTimesSingle.getKey()));
          }
  
          List&lt;Map.Entry&lt;String, OpeningTimes&gt;&gt; list = new ArrayList&lt;Map.Entry&lt;String, OpeningTimes&gt;&gt;(openingTimesMap.entrySet());
  
          Collections.sort(list, new OpeningTimesComparator());
  
          for (Entry&lt;String, OpeningTimes&gt; openingTimesSingle : openingTimesMap.entrySet()) {
              System.out.println("Key: " + openingTimesSingle.getKey() + " Value: " + openingTimesMap.get(openingTimesSingle.getKey()));
          }
      }
  }
  </code></pre>
  
  <p>Thanks in advance</p>