-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathstack.java
More file actions
32 lines (25 loc) · 716 Bytes
/
stack.java
File metadata and controls
32 lines (25 loc) · 716 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
28
29
30
31
32
// Java program to add the
// elements in the stack
import java.io.*;
import java.util.*;
class StackDemo {
// Main Method
public static void main(String[] args)
{
// Default initialization of Stack
Stack stack1 = new Stack();
// Initialization of Stack
// using Generics
Stack<String> stack2 = new Stack<String>();
// pushing the elements
stack1.push(4);
stack1.push("All");
stack1.push("Geeks");
stack2.push("Geeks");
stack2.push("For");
stack2.push("Geeks");
// Printing the Stack Elements
System.out.println(stack1);
System.out.println(stack2);
}
}