-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashMap
45 lines (32 loc) · 923 Bytes
/
HashMap
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.*;
/**
* created by VIKAS SINGH
* on 21 JAN 2016
*/
public class Solution {
public static void main(String args[]) {
// This is how you declare a HashMap
HashMap<Integer, String> hm = new HashMap<Integer, String>();
// Adding elements to HashMap
hm.put(12,"Chaitanya");
hm.put(7,"Swati");
hm.put(3,"Neeraj");
hm.put(16,"Shivani");
hm.put(17,"Vikas");
hm.put(3,"Neerajaa");
Set set = hm.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()) {
Map.Entry me = (Map.Entry) iterator.next();
System.out.println(me.getKey() + " : " + me.getValue());
}
System.out.println(hm.get(2)); // it will display null
hm.remove(12);
set = hm.entrySet();
iterator = set.iterator();
while(iterator.hasNext()) {
Map.Entry me = (Map.Entry) iterator.next();
System.out.println(me.getKey() + " : " + me.getValue());
}
}
}