title: Sorting string occurrences from text file
body: <p>I have stored strings from a file into an ArrayList, and used a HashSet to count the number of occurrences of each string.</p>
  
  <p>I am looking to list the top 5 words and their number of occurrences. I should be able to accomplish this w/o implementing a hashtable, treemap, etc. How can I go about achieving this?</p>
  
  <p>Here is my ArrayList:</p>
  
  <pre><code>List&lt;String&gt; word_list = new ArrayList&lt;String&gt;();
  
          while (INPUT_TEXT1.hasNext()) {
              String input_word = INPUT_TEXT1.next();
              word_list.add(input_word);
  
          }
  
          INPUT_TEXT1.close();
  
          int word_list_length = word_list.size();
  
  
  
          System.out.println("There are " + word_list_length + " words in the .txt file");
          System.out.println("\n\n");
  
          System.out.println("word_list's elements are: ");
  
  
  
          for (int i = 0; i&lt;word_list.size(); i++) {
                  System.out.print(word_list.get(i) + "  ");
  
              }
  
          System.out.println("\n\n");
  </code></pre>
  
  <p>Here is my HashSet:</p>
  
  <pre><code>Set&lt;String&gt; unique_word = new HashSet&lt;String&gt;(word_list);
  
      int number_of_unique = unique_word.size();
  
      System.out.println("unique worlds are: ");
  
      for (String e : unique_word) {
          System.out.print(e + " ");
  
      }
  
      System.out.println("\n\n");
  
  
      String [] word = new String[number_of_unique];
      int [] freq = new int[number_of_unique];
  
      int count = 0;
  
      System.out.println("Frequency counts : ");
  
      for (String e : unique_word) {
          word[count] = e;
          freq[count] = Collections.frequency(word_list, e);
  
  
  
          System.out.println(word[count] + " : "+ freq[count] + " time(s)");
          count++;
  
      }
  </code></pre>
  
  <p>Could it be that I am overthinking a step? Thanks in advance</p>