Few Stack related questions in Java
<pre><code>import java.util.Iterator;
import java.util.Stack;

public class StackExample {

    public static void main(String args[]){

        Stack&lt;String&gt; sk = new Stack&lt;String&gt;();

        sk.push("Hello");
        sk.push("Hello1");
        sk.push("Hello2");
        sk.push("Hello3");

        System.out.println("The Values of Stack" +sk);

        Iterator it=sk.iterator();

        System.out.println("Size before pop() :"+sk.size());

        while(it.hasNext())
        {
            String iValue=(String)it.next();
            System.out.println("Iterator value :"+iValue);
        }

        String value =(String)sk.pop();

        System.out.println("value :"+value);

        System.out.println("Size After pop() :"+sk.size());



    }

}
</code></pre>

<p>Can anyone explain me the below questions. </p>

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

<ol>
<li><p>Why do we iterate in this manner and what does the hasNext and next
do? Can i not do the same with an for loop.</p>

<pre><code>String value =(String)sk.pop();
</code></pre></li>
<li><p>What does the (String)sk.pop means... why does it not compile when i
remove the (String)</p></li>
<li><p>Can anyone lead me to some good and complex Stack examples in Java</p></li>
</ol>
