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 :: android pass object to activity 
Java :: do you need java installed for kafka 
Java :: jasypt-spring-boot 
Java :: Java Create a BufferedWriter 
Java :: how to create set java 
Java :: java stringbuilder setcharat 
Java :: eliminar el primer caracter de un string java 
Java :: android iterate through radio group java 
Java :: java get enum by ordinal 
Java :: java character for end of file 
Java :: this keyword java 
Java :: spiral traversal of matrix leetcode 
Java :: Java LogManager 
Java :: java get substring 
Java :: how to convert iso-8859-1 to utf-8 in java 
Java :: select list of values from db java 
Java :: how to put a string in gradle file and acce to it android studio 
Java :: how to send http post create request using curl command 
Java :: max int array java 
Java :: like in cypher query 
Java :: java benchmark time 
Java :: java show my form 
Java :: get SecretKey from String 
Java :: convert pdf to word in java 
Java :: java Detect Cycle in a Directed Graph 
Java :: why are my if statements not working with inputs in java 
Java :: java local function 
Java :: how to use setonclicklistener from custom view in android 
Java :: java string equals null 
Java :: jdk jre jvm 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =