Howdy. 

--

-bash-4.2$ nano -w 1118a.phps
-bash-4.2$ ls -ld 1118a.phps
-rw-r--r-- 1 dgerman faculty 10 Nov 18 15:33 1118a.phps
-bash-4.2$ date
Wed Nov 18 15:33:15 EST 2020
-bash-4.2$ pwd
/u/dgerman/apache/htdocs/c212/fall2020
-bash-4.2$

--

public class Pair implements Comparable<Pair> {
  String c; 
  int times;
  public Pair(String c, int times) {
    this.c = c; 
    this.times = times; 
  }
  public String toString() {
    return this.c + ":" + this.times;  
  }
  public int compareTo(Pair other) {
    if (this.times > other.times) return -1; // this comes first 
    else if (this.times < other.times) return 1; // this comes after other 
    else return this.c.compareTo(other.c);
  }
}

--

import java.util.Map; 
import java.util.HashMap; 
import java.util.ArrayList;
import java.util.Collections; 

public class Profile {
  public static void main(String[] args) {
    String a; 
    if (args.length == 0) a = "One banana two banana three banana four.";  
    else a = args[0];
    System.out.println("Working on: " + a); 
    Map<String, Integer> profile = new HashMap<String, Integer>(); 
    for (int i = 0; i < a.length(); i++) {
      String c = a.substring(i, i+1); 
      // System.out.println( c ); 
      if (profile.get(c) == null) profile.put(c, 1); 
      else profile.put( c , profile.get(c) + 1 ) ; // 1 ); 
      System.out.println( profile ); 
    } // the profile is build
    ArrayList<Pair> pairs = new ArrayList<Pair>(); 
    for (String c : profile.keySet()) {
      Pair pair = new Pair(c, profile.get(c));
      pairs.add(pair); 
      System.out.println( pairs ); 
    } // the arraylist to be sorted is ready 
    System.out.println( pairs ); 
    Collections.sort( pairs ); 
    System.out.println( pairs ); 
  }
}

--

import java.io.File; 
import java.util.Scanner;
import java.util.HashMap; 
import java.util.Map; 

public class Example {
  public static void main(String[] args) {
    Map<String, Integer> votes = new HashMap<String, Integer>(); 
    while (true) { 
      System.out.print("Name of file: "); 
      Scanner whatever = new Scanner(System.in); 
      String fileName = whatever.nextLine(); 
      File file = new File(fileName); 
      try { 
        Scanner in = new Scanner( file ); 
        while (in.hasNext()) {
          String token = in.next();
          System.out.println( token ); 
          if (votes.get(token) == null) votes.put(token, 1); 
          else votes.put(token, votes.get(token) + 1);
        }
        break; 
      } catch (Exception e) {
        // here:
        System.out.println("That's not a good file name!"); 
      }    
    }
    System.out.println( votes ); 
  }
}

--