forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainCollections.java
More file actions
62 lines (48 loc) · 1.86 KB
/
MainCollections.java
File metadata and controls
62 lines (48 loc) · 1.86 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
package ru.javawebinar.basejava;
import ru.javawebinar.basejava.model.Resume;
import java.util.*;
public class MainCollections {
private static final String UUID_1 = "uuid1";
private static final Resume RESUME_1 = new Resume(UUID_1, "Name1");
private static final String UUID_2 = "uuid2";
private static final Resume RESUME_2 = new Resume(UUID_2, "Name2");
private static final String UUID_3 = "uuid3";
private static final Resume RESUME_3 = new Resume(UUID_3, "Name3");
private static final String UUID_4 = "uuid4";
private static final Resume RESUME_4 = new Resume(UUID_4, "Name4");
public static void main(String[] args) {
Collection<Resume> collection = new ArrayList<>();
collection.add(RESUME_1);
collection.add(RESUME_2);
collection.add(RESUME_3);
for (Resume r : collection) {
System.out.println(r);
if (Objects.equals(r.getUuid(), UUID_1)) {
// collection.remove(r);
}
}
Iterator<Resume> iterator = collection.iterator();
while (iterator.hasNext()) {
Resume r = iterator.next();
System.out.println(r);
if (Objects.equals(r.getUuid(), UUID_1)) {
iterator.remove();
}
}
System.out.println(collection.toString());
Map<String, Resume> map = new HashMap<>();
map.put(UUID_1, RESUME_1);
map.put(UUID_2, RESUME_2);
map.put(UUID_3, RESUME_3);
// Bad!
for (String uuid : map.keySet()) {
System.out.println(map.get(uuid));
}
for (Map.Entry<String, Resume> entry : map.entrySet()) {
System.out.println(entry.getValue());
}
List<Resume> resumes = Arrays.asList(RESUME_1, RESUME_2, RESUME_3);
resumes.remove(1);
System.out.println(resumes);
}
}