title: How can I print a list (employee type) using Iterator?
body: <p><strong>Employee class:</strong></p>
  
  <pre><code>public class Employee {
  
      int empid;
      String name;
      int age;
  
      public Employee(int empid,String name,int age)
      {
          this.empid=empid;
          this.name=name;
          this.age=age;
      }
      public int getEmpid() {
          return empid;
      }
      public void setEmpid(int empid) {
          this.empid = empid;
      }
      public String getname() {
          return name;
      }
      public void setname(String name) {
          this.name = name;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      } 
  }
  </code></pre>
  
  <p><strong>Comparator class:</strong></p>
  
  <pre><code>public class Employee_comparator implements Comparator&lt;Employee&gt; {
  
      @Override
      public int compare(Employee object1, Employee object2) {
          return object1.getname().compareTo(object2.getname());
      }
  }
  </code></pre>
  
  <p><strong>Main class:</strong></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  
  public class Employee_Main {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
  
          List&lt;Employee&gt; list=new ArrayList&lt;Employee&gt;();
  
          list.add(new Employee(33186,"varun",23));
          list.add(new Employee(33187,"deepak",23));
          list.add(new Employee(33188,"apple",23));
          list.add(new Employee(33189,"rohan",23));
  
          Collections.sort(list,new Employee_comparator());
  
          for(int i=0;i&lt;list.size();i++) {
  
              System.out.print("age:"+list.get(i).getAge());
              System.out.print("empid:"+list.get(i).getEmpid());
              System.out.println("name:"+list.get(i).getname());
          }
  
          Iterator&lt;Employee&gt; itr=list.iterator();
  
          while(itr.hasNext())
          {
              System.out.println(itr.next());
          }
      }
  }
  </code></pre>
  
  <p>When I try printing by using get methods, it is working fine. But when, I try to print the elements of the list using <code>Iterator</code>, it's giving the following output:</p>
  
  <pre><code>new_.Employee@28122812new_.Employee@280d280dnew_.Employee@28172817new_.Employee@28082808
  </code></pre>