我如何在 groovy 中从变量中收集数据一段时间?
how I could collect data from variable for a while in groovy?
例如这段代码
我正在尝试使用标题来收集二维数组中的数据,但我需要使用循环来执行此操作,但我不知道该怎么做?
这是我的代码
(1..8).collect{
["date":f2[it].split(";")[0],'product':f2[it].split(";")[1], 'quant':f2[it].split(";")[2], 'weight':f2[it].split(";")[3], 'price':f2[it].split(";")[4],
}
减少到这样的程度
这是我尝试在 groovylang 中使用的代码
但是不工作我不知道是什么问题
st="date;product;quant;weight;price"
x=0
(1..8).collect{
[8.times {st[x]:f2[it].split(";")[x],; x=x+1}}
请帮帮我
假设,我们在这里讨论的是某种 CSV 文件,这会急切地创建一个包含数据的地图列表:
def fauxcsv = ["a;b;c", "1;2;3", "42;93;666"]
def head = fauxcsv.first().split(";")
println fauxcsv.tail().take(8).collect{ // skip head, take up to 8 items
[head, it.split(";")].transpose().collectEntries() // combine head and data and turn into map
}
// => [[a:1, b:2, c:3], [a:42, b:93, c:666]]
例如这段代码
我正在尝试使用标题来收集二维数组中的数据,但我需要使用循环来执行此操作,但我不知道该怎么做?
这是我的代码
(1..8).collect{
["date":f2[it].split(";")[0],'product':f2[it].split(";")[1], 'quant':f2[it].split(";")[2], 'weight':f2[it].split(";")[3], 'price':f2[it].split(";")[4],
}
减少到这样的程度
这是我尝试在 groovylang 中使用的代码
但是不工作我不知道是什么问题
st="date;product;quant;weight;price"
x=0
(1..8).collect{
[8.times {st[x]:f2[it].split(";")[x],; x=x+1}}
请帮帮我
假设,我们在这里讨论的是某种 CSV 文件,这会急切地创建一个包含数据的地图列表:
def fauxcsv = ["a;b;c", "1;2;3", "42;93;666"]
def head = fauxcsv.first().split(";")
println fauxcsv.tail().take(8).collect{ // skip head, take up to 8 items
[head, it.split(";")].transpose().collectEntries() // combine head and data and turn into map
}
// => [[a:1, b:2, c:3], [a:42, b:93, c:666]]