Iterator to call class function in java
<pre><code>package test_run;

import java.util.ArrayList;
import java.util.Iterator;

class Al_class
{
  int x;

  Al_class() {
    x=0;
  }

  void increment(){
      ++x;
  }

  int get_value(){
      return x;
  }

    ArrayList&lt;Al_class&gt; class_declare(){
    //void class_declare(){
      Al_class alc1 = new Al_class();
      Al_class alc2 = new Al_class();
      Al_class alc3 = new Al_class();
      alc1.increment();
      alc1.increment();
      alc1.increment();
      alc2.increment();

      ArrayList al = new ArrayList();
      al.add(alc1);
      al.add(alc2);
      al.add(alc3);
      return al;
  }



} ///:~

class Main
{

  public static void main(String[] args) {
    Al_class a = new Al_class();
    ArrayList&lt;Al_class&gt; b;

    b=a.class_declare();
    a.class_declare();
    System.out.print(" Arraylist size= "+ b.size());

    for (Al_class c : b ){

        System.out.print("\n" + c.get_value() + "\n");
    }
    b.remove(0);
    System.out.print(" Arraylist size= "+ b.size());

    Iterator it= b.iterator();
    while (it.hasNext()) {
        System.out.print("\n" + it.next());
        // Al_class e=it.next();
        // System.out.print("\n" + e.get_value());          
    }
  }
}
</code></pre>

<p>How can I use iterator to call the object function <code>get_value</code>? Its not a homework, but self learning.</p>
