builder for HashMap

前端 未结 15 2274
迷失自我
迷失自我 2020-11-30 00:17

Guava provides us with great factory methods for Java types, such as Maps.newHashMap().

But are there also builders for java Maps?

HashM         


        
15条回答
  •  醉酒成梦
    2020-11-30 00:43

    You can use:

    HashMap m = Maps.newHashMap(
        ImmutableMap.of("a",1,"b",2)
    );
    

    It's not as classy and readable, but does the work.

提交回复
热议问题