im currently learning stacks in java and have a quick question. what will the following code display if the stack is empty? my guess would be "true"?
System.out.开发者_如何转开发println(st.isEmpty());
Yes, it will print true
.
Running simple snippets of code is very easy (with IDEs like Eclipse - even easier), so you can verify all such assumptions with a few clicks/keystrokes.
In the future, give .jpage files a try. They provide a way in Eclipse to run small snippets of code as though they were being interpreted!
If you want to test out small snippets of code, try http://ideone.com!
Yes, it will simply return true. IsEmpty() method will return true, if no objects is available in stack container.
Stack s1 = new Stack();
s1.push(1);
s1.push(2);
s1.push(3);
s1.pop();
s1.pop();
s1.pop();
System.out.println(s1.isEmpty());
精彩评论