Java: create a list of HashMaps

前端 未结 6 581
甜味超标
甜味超标 2021-01-02 02:36

I tried to create a list of maps. In the following code, I\'m expecting to get

[{start=1,text=ye}, {start=2,text=no}]

however, I only got

6条回答
  •  Happy的楠姐
    2021-01-02 02:43

    Yes, hash map from this piece of code

    list.add(new HashMap());
    

    is never referenced. So eventually you get a list of 3 items, 2 of which are identical however.

提交回复
热议问题