What are the benefits of using an iterator in Java
<p>I was browsing over the following code example:</p>

<pre><code>public class GenericTest {

 public static void main (String[] args) {

  ArrayList&lt;String&gt; myList = new ArrayList&lt;String&gt;();
  String s1 = "one";
  String s2 = "two";
  String s3 = "three";

  myList.add(s1); myList.add(s2); myList.add(s3);
  String st;

  Iterator&lt;String&gt; itr = myList.iterator();

  while (itr.hasNext()) {
   st = itr.next();
   System.out.println(st);
  }
 }
}
</code></pre>

<p>I'm wondering what are the benefits of using an implementation of the Iterator interface instead of using a plain-old for-each loop?</p>

<pre><code> for ( String str : myList ) {
  System.out.println(str);
 }
</code></pre>

<p>If this example is not relevant, what would be a good situation when we should use the Iterator? </p>

<p>Thank you.</p>
