-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashMaps.java
55 lines (44 loc) · 1.44 KB
/
HashMaps.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Map;
import java.util.HashMap;
class HashMaps
{
public static void main(String args[])
{
HashMap<String,Integer> map = new HashMap<>();
//Hashmap Contains Person Name Age
System.out.println("Add Elements for HashMap.");
map.put("Kalpesh",18);
map.put("Kunal",18);
map.put("Darshan",20);
map.put("Dinesh",26);
map.put("Rahul",24);
System.out.println("All Key Access.");
System.out.println("ALl key :"+map.keySet());
System.out.println("\nIterate the HashMap");
for(Map.Entry<String,Integer> entry: map.entrySet())
{
System.out.println("Get Key:"+entry.getKey()+"\tGet Value:"+entry.getValue());
}
//Sample for loop
for(String keys :map.keySet())
{
System.out.println("Keys :"+keys + "\tValues :"+map.get(keys));
}
System.out.println("\nRemove key and Value:");
map.remove("Rahul");
System.out.println(map);
System.out.println("\nOnly One Key null and Value assign");
map.put(null,20);
map.put(null,19); //Only One key is Null
System.out.println(map);
System.out.println("\nMultiple Value is Null");
map.put("Nitin",null);
map.put("Sagar",null);
map.put("Mahendra",null);
System.out.println(map);
System.out.println("\nKey Contain Hashmap or Not");
System.out.println("is Hashmap Conatain Key Darshan:"+map.containsKey("Darshan"));
System.out.println("\nValue Contain Hashmap or Not");
System.out.println("is Hashmap Contain Value 20 :"+map.containsValue(20));
}
}