forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapSize.java
More file actions
30 lines (20 loc) · 721 Bytes
/
HashMapSize.java
File metadata and controls
30 lines (20 loc) · 721 Bytes
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
package com.zetcode;
import java.util.HashMap;
import java.util.Map;
public class HashMapSize {
public static void main(String[] args) {
Map<String, String> capitals = new HashMap<>();
capitals.put("svk", "Bratislava");
capitals.put("ger", "Berlin");
capitals.put("hun", "Budapest");
capitals.put("czk", "Prague");
capitals.put("pol", "Warsaw");
capitals.put("ita", "Rome");
int size = capitals.size();
System.out.printf("The size of the HashMap is %d%n", size);
capitals.remove("pol");
capitals.remove("ita");
size = capitals.size();
System.out.printf("The size of the HashMap is %d%n", size);
}
}