-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollections_framework_demo.java
More file actions
executable file
·59 lines (47 loc) · 1.93 KB
/
Copy pathcollections_framework_demo.java
File metadata and controls
executable file
·59 lines (47 loc) · 1.93 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.*;
public class DataStructureDemo {
public static void main(String[] args) {
System.out.println("=== STACK Example ===");
Stack<Integer> stack = new Stack<>();
stack.push(10);
stack.push(20);
stack.push(30);
System.out.println("Stack: " + stack);
System.out.println("Popped element: " + stack.pop());
System.out.println("Top element: " + stack.peek());
System.out.println("Stack after pop: " + stack);
System.out.println();
System.out.println("=== QUEUE Example ===");
Queue<String> queue = new LinkedList<>();
queue.add("A");
queue.add("B");
queue.add("C");
System.out.println("Queue: " + queue);
System.out.println("Removed element: " + queue.remove());
System.out.println("Front element: " + queue.peek());
System.out.println("Queue after removal: " + queue);
System.out.println();
System.out.println("=== LINKED LIST Example ===");
LinkedList<String> list = new LinkedList<>();
list.add("Node1");
list.add("Node2");
list.addFirst("Start");
list.addLast("End");
System.out.println("LinkedList: " + list);
list.remove("Node2");
System.out.println("After removing Node2: " + list);
System.out.println();
System.out.println("=== TREE Example (TreeSet) ===");
TreeSet<Integer> tree = new TreeSet<>();
tree.add(50);
tree.add(20);
tree.add(70);
tree.add(10);
System.out.println("TreeSet (sorted): " + tree);
System.out.println("First element: " + tree.first());
System.out.println("Last element: " + tree.last());
System.out.println("Tree higher than 20: " + tree.higher(20));
System.out.println();
System.out.println("=== END OF PROGRAM ===");
}
}