-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapEntry_HashMap.java
34 lines (30 loc) · 1.17 KB
/
MapEntry_HashMap.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
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class MapEntry_HashMap {
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap<>();
map.put("1", "one");
map.put("2", "two");
map.put("3", "three");
map.put("4", "four");
map.put("5", "five");
map.put("6", "six");
map.put("7", "seven");
map.put("8", "eight");
map.put("9", "nine");
map.put("10", "ten");
System.out.println("Map:" + map);
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
}
Set<Map.Entry<String, String>> entries = map.entrySet();
System.out.println("Entry Set:" + entries);
for (Entry<String, String> entry : map.entrySet()) {
System.out.println("Key:" + entry.getKey() + " Value:" + entry.getValue());
}
Set<Entry<String, String>> entries1 = map.entrySet();
System.out.println("Entry Set:" + entries1);
}
}