**Hashtable in Java**
A **Hashtable** in Java is a data structure that stores key–value pairs. It is part of the Java Collections
Framework and works similarly to HashMap but is **synchronized**, meaning it is thread-safe.
### **Features of Hashtable** 1.
Stores data in key-value pairs.
2. Keys are unique.
3. Does not allow null keys or null values.
4. Thread-safe (synchronized).
5. Based on hashing technique.
### **Syntax**
```java
Hashtable hashtable = new Hashtable<>();
```
### **Example**
```java import
[Link];
public class HashtableExample {
public static void main(String[] args) {
Hashtable table = new Hashtable<>();
[Link](1, "Apple");
[Link](2, "Banana");
[Link](3, "Cherry");
[Link]("Value at key 2: " + [Link](2));
[Link]("All elements:");
for (Integer key : [Link]()) {
[Link](key + " => " + [Link](key));
```
### **Output**
```
Value at key 2: Banana
All elements: 1 =>
Apple
2 => Banana
3 => Cherry
```
### **Advantages**
- Thread-safe
- Fast lookup due to hashing
- Good for multi-threaded applications
### **Disadvantages**
- Slower than HashMap because it is synchronized
- Does not allow null keys or values