-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCollections.java
56 lines (50 loc) · 1.77 KB
/
Collections.java
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
package com.houarizegai.datastructure.collections;
import com.houarizegai.datastructure.linkedlist.LinkedList;
import com.houarizegai.datastructure.queue.array.QueueArray;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Queue;
import java.util.Stack;
public class Collections {
public static void main(String[] args) {
// Linked list
System.out.println("\nLinked List:");
LinkedList<String> linkedList = new LinkedList<>();
linkedList.add("Hello");
linkedList.add("World");
linkedList.diplay();
linkedList.delete();
linkedList.diplay();
linkedList.delete();
// Array list
System.out.println("\nArray List:");
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("A");
arrayList.add("B");
arrayList.remove(0);
System.out.println(arrayList.toString());
// Stack
System.out.println("\nStack:");
Stack<Integer> stack = new Stack<>();
stack.push(10);
stack.push(12);
System.out.println(stack.toString());
System.out.println("Pop: " + stack.pop());
// Queue
System.out.println("\nQueue Array:");
QueueArray<String> queueArray = new QueueArray<>(2);
queueArray.add("q1");
queueArray.add("q2");
queueArray.display();
System.out.println("Remove: " + queueArray.remove());
queueArray.display();
// Hash Table
System.out.println("\nHash Table:");
Hashtable<Integer, String> hashtable = new Hashtable<>();
hashtable.put(1, "Hello");
hashtable.put(2, "World");
System.out.println(hashtable.get(1));
hashtable.remove(1);
System.out.println(hashtable.toString());
}
}