Answers for "java create map and add elements"

10

new hashmap java

Map<String, String> myMap = new HashMap<String, String>() {{
        put("a", "b");
        put("c", "d");
    }};
Posted by: Guest on May-21-2020
3

java add to map

HashMap<String, String> map = new HashMap<>();
map.put("key", "value");
Posted by: Guest on January-12-2021
1

java add element to map

map.put(key, Object);
//exemple:
Map<String, String> map = new HashMap<String, String>();
map.put("mykey", "myvalue");
Posted by: Guest on July-05-2020
0

java initialize map with values in one line

Map<String, Integer> map = Stream.of(
  new AbstractMap.SimpleImmutableEntry<>("idea", 1),    
  new AbstractMap.SimpleImmutableEntry<>("mobile", 2))
  .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Posted by: Guest on December-09-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language