title: Sorting words in order of frequency? (least to greatest)
body: <p>does any one have any idea how to sort a list of words in the order of their frequency (least to greatest) using the built in <code>collection.sort</code> and a <code>comparator&lt;string&gt;</code> interface?</p>
  
  <p>I already have a method that gets the count of a certain word in the text file. Now, I just need to create a method that compares the counts of each word and then puts them in a list sorted by the least frequency to the greatest. </p>
  
  <p>Any ideas and tips would be very much appreciated. I'm having trouble getting started on this particular method. </p>
  
  <pre><code>public class Parser implements Comparator&lt;String&gt; {
  
      public Map&lt;String, Integer&gt; wordCount;
  
      void parse(String filename) throws IOException {
          File file = new File(filename);
          Scanner scanner = new Scanner(file);
  
          //mapping of string -&gt; integer (word -&gt; frequency)
          Map&lt;String, Integer&gt; wordCount = new HashMap&lt;String, Integer&gt;();
  
          //iterates through each word in the text file
          while(scanner.hasNext()) {
              String word = scanner.next();
              if (scanner.next()==null) {
                  wordCount.put(word, 1);
              }
              else {
                  wordCount.put(word, wordCount.get(word) + 1);;
                  }
              }
              scanner.next().replaceAll("[^A-Za-z0-9]"," ");
              scanner.next().toLowerCase();
          }
  
      public int getCount(String word) {
          return wordCount.get(word);
      }
  
      public int compare(String w1, String w2) {
          return getCount(w1) - getCount(w2);
      } 
  
          //this method should return a list of words in order of frequency from least to   greatest
      public List&lt;String&gt; getWordsInOrderOfFrequency() {
          List&lt;Integer&gt; wordsByCount = new ArrayList&lt;Integer&gt;(wordCount.values());
          //this part is unfinished.. the part i'm having trouble sorting the word frequencies
          List&lt;String&gt; result = new ArrayList&lt;String&gt;();
  
  
      }
  }
  </code></pre>