import java.util.ArrayList; import java.util.Scanner; import java.util.StringTokenizer; import java.util.Collections; import java.io.FileInputStream; import java.io.FileNotFoundException; /** Driver.java - Let's read in a list of names, and use the PersonComparator * to tell the API sort() how to sort the names. */ public class Driver { public static void main(String [] args) throws FileNotFoundException { ArrayList list = new ArrayList(); Scanner in = new Scanner(new FileInputStream("input.txt")); while (in.hasNextLine()) { String line = in.nextLine(); StringTokenizer tok = new StringTokenizer(line, " "); String first = tok.nextToken(); String last = tok.nextToken(); Person p = new Person(first, last); list.add(p); } System.out.println("UNsorted list:"); for(int i = 0; i < list.size(); ++i) System.out.println(list.get(i)); // Okay, at this point we have our list of people. Time to sort! Collections.sort(list, new PersonComparator()); System.out.println("\nsorted list:"); for(int i = 0; i < list.size(); ++i) System.out.println(list.get(i)); } }