title: Sort List of Strings by Characters In Java
body: <p>I am trying to write a program to order a list of strings by most least frequent characters within the list. For example, if the list was <code>[apple, orange, banana]</code> the letter frequency within the list would be a - 5, n - 3, p - 2, e - 2,  l- 1, o - 1, r - 1, g - 1, b - 1. Since orange contains the most least frequent letters, the program would return orange, then apple then banana.</p>
  
  <p>So far I've written the code that orders all the letters in the list by frequency. But I need to apply that to find which string contains the most least frequent letters.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    Map&lt;Character, Integer&gt; elemCount = new LinkedHashMap&lt;&gt;();
      for (String word : words)
      {
          for (int i = 0; i  &lt; word.length(); i++)
          {
              if (elemCount.containsKey(word.charAt(i)))
              {
                  elemCount.put(word.charAt(i), elemCount.get(word.charAt(i)) + 1);
              }
              else
              {
                  elemCount.put(word.charAt(i), 1);
              }
          }
      }
      ArrayList&lt;Character&gt; sortedElems = new ArrayList&lt;&gt;();
      elemCount.entrySet().stream().sorted(Collections.reverseOrder
      (Map.Entry.comparingByValue())).forEach(entry -&gt; 
      { 
          for (int i = 1; i &lt;= entry.getValue(); i++)
          {
              sortedElems.add(entry.getKey());
          }
      }
      );
      System.out.println(sortedElems);
  </code></pre>