我想要一个这样的收藏
[item1: [123, 123, 2321], item2: [1231,1222,1313]]
我尝试使用这样的 map [ : [] ]
但这是不允许的。我怎样才能实现以下结构。我想使用字符串作为键添加元素:
content['item1'] << 123
最佳答案
一切正常,您使用Map
- 而不是二维数组:
def m = [item1: [123, 123, 2321], item2: [1231,1222,1313]]
m['item1'] << 1234
println(m)
如果您需要声明,可以通过以下方式完成:
Map<String, List<Integer>> m = [:]
但是它会在运行时被删除。
关于Groovy 二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30703908/