title: Why does this java iterator loop print also the first element?
body: <pre><code>import java.util.*;
  public class IteratorDemo {
  
     public static void main(String args[]) {
        // Create an array list
        ArrayList al = new ArrayList();
  
        // add elements to the array list
        al.add("C");
        al.add("A");
        al.add("E");
        al.add("B");
        al.add("D");
        al.add("F");
  
        // Use iterator to display contents of al
        System.out.print("Original contents of al: ");
        Iterator itr = al.iterator();
  
        while(itr.hasNext()) {
           Object element = itr.next();
           System.out.print(element + " ");
        }
        System.out.println();
      }
    }
  </code></pre>
  
  <p>I don't get it. If <code>al.iterator()</code> returns the first element of <code>al</code>, why if I put <code>itr.next()</code>(which should be the second I'm guessing) in <code>element</code> and then print <code>element</code> does it print the first element and not the second?</p>
  
  <p>I'm new to java. Making a parallel with c/c++, is Iterator like a pointer and Iterator.next() like the dereferenced pointer? Can someone explain to me what's actually happening at a low level when I do what's in the code?</p>