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年的作業風格問題。 –