-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhashMap.java
30 lines (23 loc) · 953 Bytes
/
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
import java.util.HashMap;
public class hashMap
{
public static void main(String[] args)
{
// Creating a new hashmap of type string as key and also string as value.
var hm = new HashMap<String, String>(2);
// Inserting the values associated with keys.
hm.put("Name", "Naveed");
hm.put("Age", "21");
hm.put("Profession", "Software Developer");
// Printing the key, Values.
System.out.println("NAME : " + hm.get("Name"));
System.out.println("AGE : " + hm.get("Age"));
System.out.println("PROFESSION : " + hm.get("Profession"));
// Returning whether the hashmap contains the 'Age' key.
System.out.println(hm.containsKey("Age"));
// Returning whether the hashmap contains the 'Naveed' value.
System.out.println(hm.containsValue("Naveed"));
// Clear the entire hashmap.
hm.clear();
}
}