Skip to content

Commit 6b2090e

Browse files
authored
Create Addition-using-hashtable.java (#368)
Here's a solution to opened issue create hashtable folder and a simple hashtable program
1 parent 82e9898 commit 6b2090e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
class AddElementsToHashtable {
5+
public static void main(String args[])
6+
{
7+
// No need to mention the
8+
// Generic type twice
9+
Hashtable<Integer, String> ht1 = new Hashtable<>();
10+
11+
// Initialization of a Hashtable
12+
// using Generics
13+
Hashtable<Integer, String> ht2
14+
= new Hashtable<Integer, String>();
15+
16+
// Inserting the Elements
17+
// using put() method
18+
ht1.put(1, "Geeks");
19+
ht1.put(2, "For");
20+
ht1.put(3, "Geeks");
21+
22+
ht2.put(1, "Geeks");
23+
ht2.put(2, "For");
24+
ht2.put(3, "Geeks");
25+
26+
// Print mappings to the console
27+
System.out.println("Mappings of ht1 : " + ht1);
28+
System.out.println("Mappings of ht2 : " + ht2);
29+
}
30+
}
31+
32+

0 commit comments

Comments
 (0)