Search
 
SCRIPT & CODE EXAMPLE
 

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

hashmap declare and initialize with values in 1 line java


Java:
new HashMap<String, String>() {{ put("Key", "Value"); }};
Comment

PREVIOUS NEXT
Code Example
Java :: java constructor overloading 
Java :: hide icon android studio 
Java :: java get attributes from class 
Java :: map java 
Java :: java basic syntax 
Java :: how to round double to 2 decimal places java 
Java :: java standard exceptions 
Java :: calculate time java 
Java :: linkedhashmap in java 
Java :: reviews button ade android studio 
Java :: java memory increase command 
Java :: hide steam games from friends 
Java :: display two dimension array java 
Java :: multiplication table using while loop in java 
Java :: 2d array java 
Java :: register watch service java 
Java :: java android development get element by id 
Java :: abstraction in java 
Java :: H2 enabling remote database creation first 
Java :: input file in java 
Java :: word count in a string using HashMap Collection 
Java :: how to put string in char array in java tutorialspoint 
Java :: java netbeans textfield only numbers 
Java :: print in java 
Java :: check if a char is a space java 
Java :: java system.out.println not working 
Java :: add to list java 
Java :: array find max in java 
Java :: java array erstellen 
Java :: priority queue java comparator 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =