title: how to sort a list of strings alphabetically in java?
body: <p>Hie.</p>
  
  <p>I am a Java beginner. I need to sort a String of names alphabetically. 
  i have a class that reads from a text file and writes the sorted file which filters by age(less than 18) but i need it to filter alphabetically, below is my implementation. Its working fine without filter by name.</p>
  
  <pre><code>        public class PatientFileProcessor {
  
              public void process(File source, File target) {
  
                  System.out.println("source"+source.getAbsolutePath());
                  System.out.println("target"+target.getAbsolutePath()); 
  
                  try {
                      writefile(target, filterbyAge(readfile(source)));
                  } catch (Exception ex) {
                      Logger.getLogger(PatientFileProcessor.class.getName()).log(Level.SEVERE, null, ex);
                  }
              }
  
              public List&lt;Patient&gt; readfile(File source) throws Exception {
                  List&lt;Patient&gt; patients = new ArrayList();
                  BufferedReader bf = new BufferedReader(new FileReader(source));
                  String s = bf.readLine();// ignore first line
                  while ((s = bf.readLine()) != null) {
                      String[] split = s.split("\\|");
                      System.out.println(Arrays.toString(split));
                      System.out.println(s+"       "+split[0]+"       "+split[1]+"       "+split[2]);
                      Date d = new SimpleDateFormat("yyyy-dd-MM").parse(split[2]);
                      patients.add(new Patient(split[0], split[1], d));
                  }
                  return patients;
              }
  
              public void writefile(File target, List&lt;Patient&gt; sorted) throws Exception {
  
                  BufferedWriter pw = new BufferedWriter(new FileWriter(target));
                  DateFormat df = new SimpleDateFormat("yyyy/dd/MM");
  
                  for (Iterator&lt;Patient&gt; it = sorted.iterator(); it.hasNext();) {
                      Patient p = it.next();
  
  
                      pw.append(p.getName() + "|" + p.getGender() + "|" + df.format(p.getDob()));
                      pw.newLine();
                  }
                  pw.flush();
              }
  
              public List&lt;Patient&gt; filterbyAge(List&lt;Patient&gt; ps) {
                  List&lt;Patient&gt; sorted = new ArrayList();
                  for (Iterator&lt;Patient&gt; it = ps.iterator(); it.hasNext();) {
                      Patient s = it.next();
                      if (calcAge(s.getDob()) &gt; 18) {
                          sorted.add(s);
                      }
  
                  }
                  return sorted;
              }
  
  
              public int calcAge(Date d) {
                  Date today = new Date();
                  long m = today.getTime() - d.getTime();
                  return (int) (m / (1000 * 60 * 60 * 24 * 365.25));
              }
  
              }
  </code></pre>
  
  <p>Patient:</p>
  
  <pre><code>import java.util.Date;
  
  public class Patient {
      private String name;
      private String gender;
      private Date dob;
  
      public Patient() {
      }
  
      public Patient(String name, String gender, Date dob) {
          this.name = name;
          this.gender = gender;
          this.dob = dob;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getGender() {
          return gender;
      }
  
      public void setGender(String gender) {
          this.gender = gender;
      }
  
      public Date getDob() {
          return dob;
      }
  }
  </code></pre>
  
  <p>how do i go about it?</p>