What is the difference between HashMap and Hashtable in Java?
Hello colleagues! I started learning the Java Collections Framework and came across two similar classes: HashMap and Hashtable. Both seem to implement the Map interface and store key-value pairs. But I noticed that in modern code everyone uses HashMap, while Hashtable is considered outdated.
I wrote a simple example where both classes behave the same:
```java
import java.util.*;
public class MapTest {
public static void main(String[] args) {
Map hashMap = new HashMap<>();
hashMap.put("key1", "value1");
hashMap.put(null, "nullValue");
System.out.println("HashMap: " + hashMap.get("key1"));
Hashtable hashtable = new Hashtable<>();
hashtable.put("key1", "value1");
// hashtable.put(null, "nullValue