-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateExample.java
More file actions
39 lines (28 loc) · 765 Bytes
/
TemplateExample.java
File metadata and controls
39 lines (28 loc) · 765 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
33
34
35
36
37
38
39
package Collection1;
import java.util.ArrayList;
class MyStack<T extends Number, E> {
T data;
ArrayList<T> stackList = new ArrayList<>();
public void push(T data) {
this.data = data;
stackList.add(this.data);
}
public void pop() {
System.out.println("Pop is " + stackList.remove(stackList.size() - 1));
}
@Override
public String toString() {
return "MyStack [ stackList=" + stackList + "]";
}
}
public class TemplateExample {
public static void main(String[] args) {
MyStack<Integer, String> myStack = new MyStack<>();
myStack.push(10);
myStack.push(20);
System.out.println("Now the Stack is " + myStack);
myStack.pop();
System.out.println("After Pop " + myStack);
MyStack<Double, String> myStack2 = new MyStack<>();
}
}