-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackPrgm.java
More file actions
37 lines (37 loc) · 869 Bytes
/
Copy pathStackPrgm.java
File metadata and controls
37 lines (37 loc) · 869 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
package collectionPrgms;
import java.util.Scanner;
import java.util.Stack;
import java.util.Collections;
public class StackPrgm {
public static void main(String[] args) {
Stack<Integer>s=new Stack<>();
Scanner sc=new Scanner(System.in);
s.push(7);
s.push(0);
s.push(2);
s.push(4);
s.push(1);
s.push(3);
System.out.println(s);
//removes the top element
s.pop();
System.out.println(s);
//displays the top element
System.out.println(s.peek());
System.out.println(s);
//removes the 1st element
s.remove(1);
System.out.println(s);
s.removeFirst();
System.out.println(s);
s.removeLast();
System.out.println(s);
System.out.println(s.empty());
System.out.println(s.size());
s.add(10);
System.out.println(s);
System.out.println(s.capacity());
s.clear();
System.out.println(s);
}
}