import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) {
Map<Integer, List<String>> multimap = new HashMap<>();
// Adding values to the multimap
multimap.put(1, new ArrayList<>());
multimap.get(1).add("Alice");
multimap.get(1).add("Amanda");
multimap.put(2, new ArrayList<>());
multimap.get(2).add("Bob");
// Iterating over the multimap
for (Map.Entry<Integer, List<String>> entry : multimap.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
// Adding another value to an existing key
multimap.get(1).add("Arnold");
System.out.println("Updated values for key 1: " + multimap.get(1));
// Checking if a specific key exists
if (multimap.containsKey(2)) {
System.out.println("Found values for key 2: " + multimap.get(2));
}
// Using lambda to iterate
multimap.forEach((key, value) -> System.out.println(key + ": " + value));
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: