title: How to sort the elements of an ArrayList according to their ascii values?
body: <p>I have read a file using Scanner and then used a HashMap and ArrayList to sort the words according to the number of occurrences of words(ascending and descending) and everything is working fine. But I want the output to be sorted in a way that it first displays numbers then uppercase and then lowercase. </p>
  
  <p>Following is my code for the same:</p>
  
  <pre><code>`Scanner scanner = new Scanner(new File("file"));
      Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();
      int count=0;
      String whole="";
      while (scanner.hasNext())
          {
          count++;
          String word = scanner.next();
          whole=whole + " " + word;
          if (map.containsKey(word))
              {
              map.put(word, map.get(word)+1);
              }
          else
              {
              map.put(word, 1);
              }
          }
  
      List&lt;Map.Entry&lt;String, Integer&gt;&gt; entries = new ArrayList&lt;Entry&lt;String,Integer&gt;&gt;( map.entrySet());
  
      Collections.sort(entries, new Comparator&lt;Map.Entry&lt;String, Integer&gt;&gt;() {
  
          @Override
          public int compare(Map.Entry&lt;String, Integer&gt; a, Map.Entry&lt;String, Integer&gt; b) {
              return a.getValue().compareTo(b.getValue());
          }
      });
  
      System.out.println("Count: " +count);
      System.out.print("Output 1(Ascending): ");
      for(int j = 0; j &lt; map.size(); j++){
          System.out.println(entries.get(j).getKey()+" "+entries.get(j).getValue());
      }
  
      System.out.print("Output 2(Descending): ");
      for(int i = 0; i &lt; map.size(); i++){
          System.out.println(entries.get(entries.size() - i - 1).getKey()+" "+entries.get(entries.size() - i - 1).getValue());
      }`
  </code></pre>
  
  <p>My input is:</p>
  
  <blockquote>
    <p>I have 10 dogs and all the dogs are of different size</p>
  </blockquote>
  
  <p>And my output is:</p>
  
  <blockquote>
    <p>Count: 12<br>
    Output 1(Ascending): all 1<br>
    the 1<br>
    size 1<br>
    are 1<br>
    and 1<br>
    of 1<br>
    have 1<br>
    I 1<br>
    different 1<br>
    10 1<br>
    dogs 2<br>
    Output 2(Descending): dogs 2<br>
    10 1<br>
    different 1<br>
    I 1<br>
    have 1<br>
    of 1<br>
    and 1<br>
    are 1<br>
    size 1<br>
    the 1<br>
    all 1            </p>
  </blockquote>
  
  <p>Desired output:</p>
  
  <blockquote>
    <p>dogs 2 \since it has more number of occurrences than any other word<br>
    10 1 \since it is a number<br>
    I 1 \since it is an uppercase letter<br>
    have 1 \followed by all the lowercase words </p>
  </blockquote>