-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashmapToHashtable.java
More file actions
38 lines (29 loc) · 1.05 KB
/
Copy pathHashmapToHashtable.java
File metadata and controls
38 lines (29 loc) · 1.05 KB
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
package Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
public class HashmapToHashtable {
public static void main(String[] args) {
Map <String, Integer> hm = new HashMap<>();
hm.put("One",1);
hm.put("Two",2);
hm.put("Three",3);
hm.put("Four",4);
hm.put("Five",5);
hm.put("Six",6);
Hashtable< String, Integer> ht = new Hashtable<>(hm);
System.out.println("Mappings of hashtable : " + ht);
System.out.println("Size of map is:- " + ht.size());
System.out.println(ht);
if (ht.containsKey("Four")) {
Integer a = ht.get("Four");
System.out.println("value for key" + " \"Four\" is:- " + a);
}
// Update the value at key 2
ht.put("Six", 066);
ht.remove("Four");
System.out.println("Mappings of hashtable : " + ht);
for (Map.Entry<String, Integer> e : ht.entrySet())
System.out.println(e.getKey() + " " + e.getValue());
}
}