Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to instantiate hashmap in java

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");
}
Comment

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");
Comment

PREVIOUS NEXT
Code Example
Java :: array to arraylist 
Java :: convert optional object to object java 
Java :: how to split a string in java 
Java :: change status bar color android programmatically 
Java :: java biginteger multiply 
Java :: ++i vs i++ java 
Java :: sprint jpa properties for application.yml 
Java :: get logged-in user in Spring Security 
Java :: print to console in java 
Java :: java string array 
Java :: how to check grant permissions in android 
Java :: java read first line of file 
Java :: string startswith java 
Java :: how to iterate hashmap java 
Java :: how to check my java heap space size 
Java :: minecraft chunk size 
Java :: java int to double 
Java :: import random java 
Java :: java string split from input string 
Java :: java string remove more than one space 
Java :: Loop Structure in Java 
Java :: object to string in java 
Java :: iterator java 
Java :: java random usage 
Java :: gradle reflections 
Java :: check instance of java 
Java :: fill an array with random numbers between 1 and 100 java 
Java :: java return list 
Java :: write input stream to file java 
Java :: regex pattern for date validation 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =