forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackDemo.java
More file actions
27 lines (19 loc) · 722 Bytes
/
StackDemo.java
File metadata and controls
27 lines (19 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package stack;
import java.util.Stack;
public class StackDemo {
public static void main(String[] args) {
Stack<String> stack = new Stack();
stack.push("Andrew");
stack.push("Tracy");
stack.push("Kobe");
stack.push("James");
System.out.println(stack);
// Looks at the object at the top of this stack without removing it from the stack.
stack.peek();
//Removes the object at the top of this stack and returns that object as the value of this function.
stack.pop();
//Returns the 1-based position where an object is on this stack.
System.out.println(stack.search("Tracy"));
System.out.println(stack);
}
}