File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments