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

后端 未结 14 2380
野趣味
野趣味 2020-11-22 10:58

Is there some way of initializing a Java HashMap like this?:

Map test = 
    new HashMap{\"test\":\"test\",\"test\         


        
14条回答
  •  渐次进展
    2020-11-22 11:32

    If you need to place only one key-value pair, you can use Collections.singletonMap(key, value);

提交回复
热议问题