title: Fetch data from List using iterator
body: <p>I am trying to fetch the data using List but by using iterator. It is displaying me the object. How can I fetch the data from it?  </p>
  
  <pre><code>import java.util.*;
      class Getter_Setter
      {
          int id;
          String name;
          public List&lt;Getter_Setter&gt; buckets;
          public String getName()
          {
              return name;
          }
          public int getId()
          {
              return id;
          }
          public void setId(int id)
          {
              this.id=id;
          }
          public void setName(String name)
          {
              this.name=name;
          }
          public void setGetter_Setter(List&lt;Getter_Setter&gt; buck)
          {
              this.buckets=buck;
          }
      }
      class Simple
      {
          public static void main(String arg[])
          {
              run();
          }
          public static void run()
          {
  
              List&lt;Getter_Setter&gt; getList=sum();
              Iterator itr=getList.iterator();
              while(itr.hasNext())
              {
                  System.out.println(itr.next());
              }
          }
          public static List&lt;Getter_Setter&gt; sum()
          {
              List&lt;Getter_Setter&gt; list=new ArrayList&lt;Getter_Setter&gt;();
              Getter_Setter get=new Getter_Setter();
              get.setId(30);
              get.setName("Hanish");
  
              System.out.println(get.getId());
              System.out.println(get.getName());
              list.add(get);
              return  list;
          }
      }
  </code></pre>