-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHashMapDemo.java
More file actions
38 lines (29 loc) · 830 Bytes
/
HashMapDemo.java
File metadata and controls
38 lines (29 loc) · 830 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
30
31
32
33
34
35
36
37
38
import java.util.*;
class HashMapDemo
{
public static void main(String args[])
{
HashMap hashMap = new HashMap();
hashMap.put("Prabhu",100);
hashMap.put("Deep",200);
hashMap.put("Singh",300);
hashMap.put("Banga",400);
System.out.println(hashMap);
System.out.println(hashMap.put("Prabhu",100));
Set set = hashMap.keySet();
System.out.println(set);
Collection collection = hashMap.values();
System.out.println(collection);
Set entrySet = hashMap.entrySet();
System.out.println(entrySet);
Iterator itr = entrySet.iterator();
while(itr.hasNext())
{
Map.Entry mapEntry = (Map.Entry) itr.next();
System.out.println(mapEntry.getKey()+", "+mapEntry.getValue());
if(mapEntry.getKey().equals("Prabhu"))
mapEntry.setValue(1000);
}
System.out.println(hashMap);
}
}