Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 使用groovy以列表作为值迭代映射时出现的问题_List_Groovy_Hashmap - Fatal编程技术网

List 使用groovy以列表作为值迭代映射时出现的问题

List 使用groovy以列表作为值迭代映射时出现的问题,list,groovy,hashmap,List,Groovy,Hashmap,以下是创建地图和访问地图的Groovized版本: key = abc value=[hello1, world1, sample1, sample1] size 34 输出: 如果要将列表转换为数组,只需执行以下操作: key: abc, list: [hello1, world1, sample1, sample1], and size: 4 key: bcd, list: [hello2, world2, sample2, sample2], and size: 4 为什么要将列表转

以下是创建地图和访问地图的Groovized版本:

key = abc value=[hello1, world1, sample1, sample1]

size 34
输出:

如果要将列表转换为数组,只需执行以下操作:

key: abc, list: [hello1, world1, sample1, sample1], and size: 4
key: bcd, list: [hello2, world2, sample2, sample2], and size: 4

为什么要将列表转换为GString data=${e.value}?如果需要传递字符串[]而不是列表,则可以简单地将其强制转换为:[a,b,c],因为不需要字符串[]数据=${e.value}。只需使用data=e.value
def map = [abc:['hello1', 'world1','sample1', 'sample1'], bcd:['hello2', 'world2','sample2', 'sample2']]
map.collect{ println "key: ${it.key}, list: ${it.value}, and size: ${it.value.size()}" }
key: abc, list: [hello1, world1, sample1, sample1], and size: 4
key: bcd, list: [hello2, world2, sample2, sample2], and size: 4
def list = ['hello1', 'world1','sample1', 'sample1']
assert list instanceof List
def array = list as String[]
assert array instanceof String[]
assert !(array instanceof List)