티스토리 뷰

공부

[Java] HashMap initialize directly

승가비 2021. 11. 28. 00:03
728x90
Map<String, String> myMap = new HashMap<String, String>() {{
        put("a", "b");
        put("c", "d");
    }};

https://stackoverflow.com/questions/6802483/how-to-directly-initialize-a-hashmap-in-a-literal-way

 

How to directly initialize a HashMap (in a literal way)?

Is there some way of initializing a Java HashMap like this?: Map<String,String> test = new HashMap<String, String>{"test":"test","test":"test"}; What would be the correct syntax? I

stackoverflow.com

 

728x90
댓글