title: Java sorting a Pojo using comparable
body: <p>The output of the following program is not what I expected it to come. What is wrong in this program? Please suggest.</p>
  
  <p>[Hello113 
  , Hello380 
  , Hello293 
  , Hello290 
  , Hello246 
  , Hello456 
  , Hello797 
  , Hello888 
  , Hello981 
  ]</p>
  
  <p><strong>EDIT</strong>: I wanted to do this in this way only. Not using collections.sort().</p>
  
  <pre><code>   public class Sample {
  
      public static void main(String[] args) {
          Random random = new Random(10);
  
          List&lt;Employee&gt; employees = new ArrayList&lt;Employee&gt;();
          for (int i=0;i&lt;10;i++)
          {
              Employee e = new Employee(i,"Hello"+random.nextInt(1000));
              employees.add(e);
          }
          System.out.println(employees);
      }
  
      }
  
      class Employee implements Comparable&lt;Employee&gt;
      {
      private int empNo;
      private String empName;
  
      public int getEmpNo() {
          return empNo;
      }
      public void setEmpNo(int empNo) {
          this.empNo = empNo;
      }
      public String getEmpName() {
          return empName;
      }
      public void setEmpName(String empName) {
          this.empName = empName;
      }
  
      Employee(int empNo,String empName)
      {
          this.empName=empName;
          this.empNo=empNo;
      }
  
      @Override
      public String toString() {
  
          return empName+" \n";
      }
  
      @Override
      public int compareTo(Employee o) {
  
          return this.getEmpName().compareTo(o.getEmpName());
      }
  </code></pre>
  
  <p>}</p>