hashmap key value pair example
Example 1: java hashmap syntax
import java.util.HashMap;
HashMap<String, String> capitalCities = new HashMap<String, String>();
capitalCities.put("England", "London");
capitalCities.put("Germany", "Berlin");
capitalCities.put("Norway", "Oslo");
capitalCities.put("USA", "Washington DC");
System.out.println(capitalCities);
Map<String, Integer> stGrade = new HashMap<String, Integer>();
stGrade.put("aaron", new Integer(90));
stGrade.put("isaac", new Integer(100));
stGrade.put("john", new Integer(35));
stGrade.put("mohammad", new Integer(100));
stGrade.get("mohammad");
stGrade.get("aaron");
stGrade.get("john");
stGrade.get("isaac");
Example 2: hashmaps java
import java.util.HashMap;
HashMap<Int, String> examplehashmap=new HashMap<>();
{
examplehashmap.put(5, "example");
};
examplehashmap.get(5);
Example 3: how to create a hashmap in java
HashMap<Integer,String> map=new HashMap<Integer,String>();