List with two different object need to sort
<p>ArrayList has two different class /objects</p>

<pre><code>   - Student class has 2 fields --&gt; NAME and ID

   - Employee class has 2 fields --&gt; NAME and ID  
</code></pre>

<p>need to sort based on <strong>ID field</strong>. Could you please help me on this thanks. </p>

<p>My suggestion is to use comparator could please help me on java code.</p>

<pre><code>class Emp {
  String name;
  int number;
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
  public int getNumber() { return number; }
  public void setNumber(int number) { this.number = number; }
}

class Student {
  String name;
  int number;
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
  public int getNumber() { return number; }
  public void setNumber(int number) { this.number = number; }
}

class empcomparator implements Comparator {
  @Override
  public int compare(Object o1, Object o2) {
   String a = ((emp) o1).getName();
   String b = ((student) o2).getName();
   return a.compareTo(b); return 1;
  }
}
</code></pre>

<p>main class my code:</p>

<pre><code>Emp emp = new Emp();
emp.setName("test1");
emp.setNumber(11);
Student stud= new Student ();
stud.setName("test2");
stud.setNumber(22);
List&lt;Object&gt; studentlist = new ArrayList&lt;Object&gt;();
studentlist.add(emp);
studentlist.add(stud);
Collections.sort(studentlist, new empcomparator());
</code></pre>

<p>List contain 100 object like this need to sort based on id. Please suggest me nice idea.</p>