This repository was archived by the owner on Feb 18, 2020. It is now read-only.
forked from bliblidotcom/training-java-future-program
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectionsTest.java
More file actions
Latest commit
37 lines (33 loc) · 1 KB
/
Copy pathCollectionsTest.java
File metadata and controls
37 lines (33 loc) · 1 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
importjava.util.*;
publicclassCollectionsTest {
publicstaticvoidmain(String[] args){
//ArrayList
List<String> names = newArrayList<>();
names.add("ABC");
names.add("Budi");
names.add("Andy");
names.add(null);
//names.add(stringSet); //Compile error due to different object type
for(Stringname : names){
System.out.println(name);
}
//Set
Set<String> stringSet = newHashSet<>();
stringSet.add("String 1");
stringSet.add("String 1");
stringSet.add("String 2");
stringSet.add(null);
//stringSet.add(names); //Compile error due to different object type
for(Stringstr : stringSet){
System.out.println(str);
}
//Map
Map<String, Integer> scoreByName = newHashMap<>();
scoreByName.put("Oliver", 100);
scoreByName.put(null, 19);
//scoreByName.put(names, 21); //Compile error due to different object type
for (Map.Entry<String, Integer> entry : scoreByName.entrySet()){ //Prints from last item
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}