import java.util.Iterator;
import java.util.Stack;
public class StackExample {
public static void main(String args[]){
Stack<String> sk = new Stack<String>();
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());
}
}
任何人都可以解释我下面的问题。在Java中很少有堆栈相关的问题
while(it.hasNext()){
String iValue=(String)it.next();
System.out.println("Iterator value :"+iValue);
}
为什么我们反复以这种方式又是什么的hasNext和next 吗?我可以做一个for循环吗?
String value =(String)sk.pop();
什么的(字符串)sk.pop指...为什么它不能编译,当我 删除(字符串)
谁能带我到一些很好的和复杂的协议栈的例子在Java中
3.我从来没有见过堆栈使用,除了在Java开发12年的作业风格问题。 –