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");
Java:
new HashMap<String, String>() {{ put("Key", "Value"); }};