forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMap.java
More file actions
29 lines (23 loc) · 714 Bytes
/
SimpleMap.java
File metadata and controls
29 lines (23 loc) · 714 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
import java.util.HashMap;
import java.util.Map;
public class SimpleMap
{
public static void main(String[] args)
{
SimpleMap simpleMap = new SimpleMap();
simpleMap.demo();
}
private void demo()
{
Map<String, String> countries = new HashMap<String, String>();
countries.put("USA", "United States");
countries.put("MEX", "Mexico");
countries.put("CAN", "Canada");
System.out.println(countries.get("USA"));
System.out.println(countries.get("CAN"));
countries.put("USA", "United States 2");
System.out.println(countries.get("USA"));
countries.remove("USA");
System.out.println(countries);
}
}