Question : new hashmap java
Answered by : fair-fly
Map<String, String> myMap = new HashMap<String, String>() {{ put("a", "b"); put("c", "d"); }};
Source : https://stackoverflow.com/questions/6802483/how-to-directly-initialize-a-hashmap-in-a-literal-way | Last Update : Thu, 28 May 20
Question : java 11 initialize map
Answered by : skandal
Map<String, String> emptyMap = Map.of();
Map<String, String> singletonMap = Map.of("key1", "value");
Map<String, String> map = Map.of("key1","value1", "key2", "value2");
Source : https://www.baeldung.com/java-initialize-hashmap | Last Update : Mon, 29 Jun 20
Question : initialize hashmap with values
Answered by : funnyname
public static Map<String, String> articleMapOne;
static { articleMapOne = new HashMap<>(); articleMapOne.put("ar01", "Intro to Map"); articleMapOne.put("ar02", "Some article");
}
Source : https://www.baeldung.com/java-initialize-hashmap | Last Update : Wed, 18 Aug 21
Question : initialize hashmap with values
Answered by : lucas-pauw9cuw3gol
Map<String, String> doubleBraceMap = new HashMap<String, String>() {{ put("key1", "value1"); put("key2", "value2");
}};
Source : https://www.baeldung.com/java-initialize-hashmap | Last Update : Fri, 10 Dec 21
Question : hashmap declare and initialize with values in 1 line java
Answered by : wicked-wolf-kfrr7ktv1iyg
Java:
new HashMap<String, String>() {{ put("Key", "Value"); }};
Source : | Last Update : Wed, 01 Dec 21
Question : Initialize HashMap Java
Answered by : brice
public static Map<String, Object> map(Object... keyValues) { Map<String, Object> map = new HashMap<>(); for (int i = 0; i < keyValues.length; i = i + 2) { map.put((String) keyValues[i], keyValues[i + 1]); } return map;
}
// usage
Map<String, String> student = MapUtils.map("firstname", "Jack", "age", "18");
Source : | Last Update : Sat, 10 Sep 22
Question : java hashmap initialize
Answered by : you
import java.util.HashMap;
public class HashMapExample { public static void main(String[] args) { // Initialize a HashMap HashMap<Integer, String> hashMap = new HashMap<>(); // Add elements to the HashMap hashMap.put(1, "Apple"); hashMap.put(2, "Banana"); hashMap.put(3, "Orange"); // Print the HashMap System.out.println(hashMap); }
}
Source : | Last Update : Tue, 19 Sep 23