-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jdk09.java
66 lines (55 loc) · 1.94 KB
/
Jdk09.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
57
58
59
60
61
62
63
64
65
66
package samples.jdk09;
import samples.jdk16.Country;
import java.util.*;
public class Jdk09 {
/**
* Shows how to use Collection Factories
* @param args
*/
public static void main(String[] args) {
collectionFactories();
// traditionalCollectionCreation();
}
private static void traditionalCollectionCreation() {
List<Integer> numberList = new ArrayList<>();
numberList.add(1);
numberList.add(2);
numberList.add(3);
numberList.add(4);
System.out.println(numberList);
List<Country> countryList = new ArrayList<>();
countryList.add(new Country("Brazil", "South America"));
countryList.add(new Country("Portugal", "Europe"));
System.out.println(countryList);
Map<Integer, String> numberMap = new HashMap<>();
numberMap.put(1, "One");
numberMap.put(2, "Two");
numberMap.put(3, "Three");
System.out.println(numberMap);
Set<Character> charSet = new HashSet<>();
charSet.add('a');
charSet.add('e');
charSet.add('i');
charSet.add('o');
charSet.add('u');
System.out.println(charSet);
}
/**
* Shows how to use the convenience methods of
* from collections such as {@link List}, {@link Set} and {@link Map}.
* @see <a href="https://openjdk.org/jeps/269>JEP 269</a>
*/
private static void collectionFactories() {
List<Integer> numberList = List.of(1, 2, 3, 4);
System.out.println(numberList);
List<Country> countryList = List.of(
new Country("Brazil", "South America"),
new Country("Portugal", "Europe")
);
System.out.println(countryList);
Map<Integer, String> numberMap = Map.of(1, "One", 2, "Two", 3, "Three");
System.out.println(numberMap);
Set<Character> charSet = Set.of('a', 'e', 'i', 'o', 'u');
System.out.println(charSet);
}
}