title: How to sort the words by their frequency
body: <p>I take an input text file, convert it to an array, sort the array, and then get the frequencies of each word. I can't figure out how to sort them according to their frequencies, from highest to lowest, without importing lots of things (which is what I am trying to do):</p>
  
  <pre><code>//find frequencies
      int count = 0;
      List&lt;String&gt; list = new ArrayList&lt;&gt;();
      for(String s:words){
          if(!list.contains(s)){
              list.add(s);
          }
      }
      for(int i=0;i&lt;list.size();i++){
          for(int j=0;j&lt;words.length;j++){
              if(list.get(i).equals(words[j])){
                  count++;
              }
          }
  
          System.out.println(list.get(i) + "\t" + count);
          count=0;
      }
  </code></pre>
  
  <p>This returns the words with their frequencies in an unsorted order, for example:</p>
  
  <pre><code>the 3
  with 7
  he 8
  </code></pre>
  
  <p>etc.</p>
  
  <p>I want this to be sorted like:</p>
  
  <pre><code>he 8
  with 7
  the 3
  </code></pre>