-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpperBoundWildCardMeth13.java
47 lines (36 loc) · 1.13 KB
/
UpperBoundWildCardMeth13.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
package com.company;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class UpperBoundWildCardMeth13 {
public static Map<? extends String,? extends Number> test(Map<? extends String,? extends Number> map) {
System.out.println("Set elements: " + map);
for (String key : map.keySet()) {
System.out.println("Keys ="+ key);
}
for (Number num : map.values()) {
System.out.println(num);
}
Iterator<? extends String> it = map.keySet().iterator();
while (it.hasNext()) {
System.out.println("Keys=" + it.next());
}
Iterable<? extends Number> it2 = map.values();
for (Number n : it2) {
System.out.println("Values =" +n);
}
for( Map.Entry<? extends String,? extends Number> entry : map.entrySet()){
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
return map;
}
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
map.put("One", 1);
map.put("Two", 2);
map.put("Three", 3);
map.put("Four", 4);
map.put("Five", 5);
test(map);
}
}