Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Initialize HashMap Java

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");
 
PREVIOUS NEXT
Tagged: #Initialize #HashMap #Java
ADD COMMENT
Topic
Name
8+6 =