Java.util.Stack

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Java.util.Stack

This Java example program shows how to use Java.util.Stack

[edit] Java Source Code

  • Package: example.stack
  • File: StackExample.java
package example.stack;
 
import java.util.Stack;
 
public class StackExample {
    public static void main(String args[]) {
	Stack s = new Stack();
	s.push("Java");
	s.push("Source");
	s.push("and");
 
	System.out.println("Next: " + s.peek());
	s.push("Support");
	System.out.println(s.pop());
	s.push(".");
	int count = s.search("Java");
	while (count != -1 && count > 1) {
	    s.pop();
	    count--;
	}
	System.out.println(s.pop());
	System.out.println(s.empty());
    }
}

[edit] What Result You Can Get

Run the program, you will get:

Next: and
Support
Java
true

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools