title: collections for sorting employee details by id & firstname
body: <p>I have written a code to sort name by id and firstname. </p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  public class TestEmployeeSort  {
  
      /**
       * @param args
       */
      public static void main(String[] args) throws IOException {
          // TODO Auto-generated method stub
          String option=null;
          System.out.println("Enter on which order sorting should be done \n1.Id \n2.FirstName \n3.LastName");
          List&lt;Employee&gt; coll = Name_Insert.getEmployees();
  
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
          option=br.readLine();
  
          int a=Integer.parseInt(option);
  
               switch(a)
               {
               case 1:
               Collections.sort(coll);
               printList(coll);
               break;
               case 2:
               Collections.sort(coll,new EmpSortByFirstName());// sort method   
               printList(coll);
               break;
               case 3:
               Collections.sort(coll,new SortByLastName());// sort method   
               printList(coll);
               }
               } 
      private static void printList(List&lt;Employee&gt; list) {
          System.out.println("EmpId\tFirstName\tLastName\tDate Of Joining\tDate of Birth");
  
          for (int i=0;i&lt;list.size();i++) {  
              Employee e=list.get(i);
              System.out.println(e.getEmpId() + "\t" + e.getFirstName() + "\t" + e.getLastname() +"\t" + e.getDate_Of_Joining()+"\t"+e.getDate_Of_Birth());
              }
          }
  
      }
  </code></pre>
  
  <p>for sorting by id and first name i have this code in the Sort_this class</p>
  
  <pre><code>public class EmpSortByFirstName implements Comparator&lt;Employee&gt;{ 
          public int compare(Employee o1, Employee o2) {  
              return o1.getFirstName().compareTo(o2.getFirstName());    }}
  </code></pre>
  
  <p>similarly for id.
  Now i want to change my program like i have to get input from uset on which basis you want to sort. If the user gives id, I have to sort by id. If the user gives firstname then sort by first name. I want to use if statement. If user enters 1 it has to sort by id 2 it has to sort by first name</p>