-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCollection.java
More file actions
158 lines (115 loc) · 3.2 KB
/
Copy pathSimpleCollection.java
File metadata and controls
158 lines (115 loc) · 3.2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.Iterator;
public class SimpleCollection {
public static void main(String[] args) {
// TODO Auto-generated method stub
// List
System.out.println("List\n");
Integer i1 = 30;
Integer i2 = 20;
List<Integer> list = new ArrayList<>();
list.add(i1);
list.add(i2);
list.add(15);
list.add(18);
list.add(12);
list.add(49);
System.out.println(list);
list.remove(i2);
System.out.println(list);
List<Student> students = new ArrayList<>();
Student s1 = new Student(101, "Naoe", 74);
students.add(s1);
students.add(new Student(102, "Joker", 72));
System.out.println(students);
Iterator<Student> s = students.iterator();
while (s.hasNext()) {
System.out.println(s.next());
}
System.out.println();
System.out.println("_________________________________\n");
// String
System.out.println("String");
Set<String> set = new HashSet<>();
String str1 = "ABC";
String str2 = "DEF";
set.add(str1);
set.add(str2);
set.add("GHI");
System.out.println(set);
set.remove("GHI");
System.out.println(set);
Set<String> skillset = new HashSet<>();
skillset.add(str1);
skillset.add(str2);
skillset.add("PQR");
skillset.add("QWE");
skillset.add("RTY");
skillset.add("UIO");
System.out.println(skillset);
skillset.remove("PQR");
Iterator<String> i = skillset.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}
System.out.println();
System.out.println("_________________________________\n");
// Queue
System.out.println("Queue");
Queue<String> names = new PriorityQueue<>();
names.add("Cyber");
names.add("Tom");
names.add("Joy");
names.add("Troy");
System.out.println(names);
names.remove("Troy");
Iterator<String> j = names.iterator();
while (j.hasNext()) {
System.out.println(j.next());
}
System.out.println();
// Map
System.out.println("Map");
Map<String, String> login = new HashMap<>();
login.put("Naoe", "Pass@123");
login.put("Cyber", "Pass@789");
login.put("Naoe", "Pass@098");
System.out.println(login);
System.out.println("Password is " + login.get("Naoe"));
Map<Integer, String> studentList = new HashMap<>();
studentList.put(1, "Cyber");
studentList.put(2, "Joker");
studentList.put(3, "Naoe");
System.out.println(studentList);
System.out.println("Student name : " + studentList.get(2));
System.out.println();
System.out.println("_________________________________\n");
// Stack
System.out.println("Stack");
Stack<Integer> numstack = new Stack<>();
numstack.push(10);
numstack.push(20);
numstack.push(30);
numstack.push(40);
numstack.push(50);
numstack.push(60);
System.out.println(numstack);
numstack.pop();
System.out.println(numstack);
System.out.println("On top of stack : " + numstack.peek());
int lastPopped = 0;
while (!numstack.isEmpty()) {
lastPopped = numstack.pop();
}
System.out.println("Last popped element: " + lastPopped);
System.out.println("_________________________________\n");
}
}