Map<String, String> doubleBraceMap = new HashMap<String, String>() {{
put("key1", "value1");
put("key2", "value2");
}};
public static Map<String, String> articleMapOne;
static {
articleMapOne = new HashMap<>();
articleMapOne.put("ar01", "Intro to Map");
articleMapOne.put("ar02", "Some article");
}
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");