-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashMapMethods.java
64 lines (46 loc) · 1.71 KB
/
HashMapMethods.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
56
57
58
59
60
61
62
63
64
package methodExamples;
import java.util.*;
public class HashMapMethods
{
public static void main(String[] args)
{
HashMap<Integer,String> hm=new HashMap<Integer,String>();
System.out.println("Initial list of elements: "+hm);
hm.put(100,"A");
hm.put(101,"V");
hm.put(102,"R");
System.out.println("After invoking put() method ");
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
hm.putIfAbsent(103, "G");
System.out.println("After invoking putIfAbsent() method ");
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
HashMap<Integer,String> map=new HashMap<Integer,String>();
map.put(104,"R");
map.putAll(hm);
System.out.println("After invoking putAll() method ");
for(Map.Entry m:map.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
map.remove(100);
System.out.println("After remove() method ");
System.out.println("Updated list of elements:");
hm.replace(102, "G");
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
System.out.println("Updated list of elements:");
hm.replace(101, "V", "R");
for(Map.Entry m:hm.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
}
}