Java ArrayList and HashMap on-the-fly

后端 未结 7 1148
甜味超标
甜味超标 2021-01-31 07:07

Can someone please provide an example of creating a Java ArrayList and HashMap on the fly? So instead of doing an add() or put()

7条回答
  •  旧巷少年郎
    2021-01-31 07:56

    A nice way of doing this is using Google Collections:

    List list = ImmutableList.of("A", "B", "C");
    
    Map map = ImmutableMap.of(
      1, "A",
      2, "B",
      3, "C");
    

提交回复
热议问题