-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashtable1.java
More file actions
40 lines (28 loc) · 860 Bytes
/
Copy pathHashtable1.java
File metadata and controls
40 lines (28 loc) · 860 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
39
40
package testJava;
import java.util.Hashtable;
import java.util.Map;
public class Hashtable1
{
public static void main(String[] args)
{
// Create a new Hashtable
Hashtable<String, Integer> ht = new Hashtable<>();
// Add key-value pairs to the Hashtable
ht.put("Apple", 25);
ht.put("Banana", 30);
ht.put("Cherry", 35);
ht.put("Oragne", 40);
// Get the value for a specific key
int value = ht.get("Banana");
System.out.println("Banana: " + value);
// Remove a key-value pair
ht.remove("Cherry");
// Check if a key is in the Hashtable
boolean containsKey = ht.containsKey("Apple");
System.out.println("Contains key 'Apple' : " +containsKey);
for(Map.Entry m:ht.entrySet())
{
System.out.println(m.getKey()+" "+m.getValue());
}
}
}