how to create a hashmap in java code example
Example 1: new hashmap java
Map<String, String> myMap = new HashMap<String, String>() {{
put("a", "b");
put("c", "d");
}};
Example 2: 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 3: declare hashmap java
Map<String, Integer> d = new HashMap<>();
Example 4: java hashmap example
Map< String,Integer> hm =
new HashMap< String,Integer>();
hm.put("a", new Integer(100));
hm.put("b", new Integer(200));
hm.put("c", new Integer(300));
hm.put("d", new Integer(400));
Example 5: declare a hashmap in java
HashMap<Integer,String> map=new HashMap<Integer,String>();
Example 6: how to create a hashmap in java
HashMap<Integer,String> map=new HashMap<Integer,String>();