-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapExample.java
More file actions
45 lines (29 loc) · 1.15 KB
/
HashMapExample.java
File metadata and controls
45 lines (29 loc) · 1.15 KB
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
import java.util.*;
public class HashMapExample {
public static void main(String[] args)
{
HashMap<String,String> countries = new HashMap<String,String>();
// Adding elements
countries.put("INDIA","NEW DELHI");
countries.put("USA","WASHINGTON DC");
countries.put("NEPAL","KATHMANDU");
countries.put("BANDLADESH","DHAKA");
countries.put("CHINA","BEJEING");
countries.put("RUSSIA","MOSCOW");
System.out.println(countries);
System.out.println("------------------------------------------------------------");
countries.remove("USA");
System.out.println(countries);
System.out.println(countries.get("RUSSIA"));
// countries.clear(); // clear all the elements from the hashmap
countries.replace("CHINA","PAKISTAN");
System.out.println(countries);
System.out.println( countries.containsKey("England"));
System.out.println( countries.containsValue("DHAKA"));
for(String i : countries.keySet() )
{
System.out.println(i + "\t"+ "=");
System.out.println(countries.get(i));
}
}
}