Using iterator interface or for each statement in Java
<pre><code>Stack&lt;String&gt; sk = new Stack&lt;String&gt;();

sk.push("Hello");
sk.push("Hello1");
sk.push("Hello2");
</code></pre>

<p>There are two ways i am iterating this Stack Object. </p>

<pre><code>for(String s : sk){
   System.out.println("The Values of String in SK" +sk);
}
</code></pre>

<p>// Way two.. </p>

<pre><code>Iterator&lt;String&gt; it=sk.iterator();
    while(it.hasNext())
    {
        String iValue=(String)it.next();
        System.out.println("Iterator value :"+iValue);
    }
</code></pre>

<ol>
<li>What is the difference between these two?</li>
<li>Any Advantage if i choose one among them?</li>
<li>Which is the preferred way of iterating?</li>
</ol>
