List 使用groovy以列表作为值迭代映射时出现的问题
以下是创建地图和访问地图的Groovized版本: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 为什么要将列表转
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)