Creating a Type-Specific Map: creates a map whose keys are Integer objects and values are String objects.
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] argv) {
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "first");
map.put(2, "second");
// map.put(1, 2); <- Syntax error
}
}
Related examples in the same category