I have defined the array
def sample1 = ["A","B","C","D"] as String[]
..
..
def sample9 = ["555","454","678","456"] as String[]
def p = ["1","2","3","4"] as String[]
for (k=0; k <= 4; k++) {
setValues(sample1[k].concat(p[k]), sample9[k])
} `
I'm trying to get values like:
A1 = 555
B2 = 454
but on execution I get an error:
groovy.lang.MissingMethodException: No signature of method: Script7.setValues() is applicable for argument types: (java.lang.String, java.lang.String) values: [A1, [555]] Possible solutions: getClass() error at line: XX
Could anyone help around? Can we set the values for 1 array with another? If so please help me out on this
You can combine the your lists, transpose them and then create the map with collectEntries
. eg
def sample1 = ["A","B","C","D"]
def sample9 = ["555","454","678","456"]
def p = ["1","2","3","4"]
println([sample1, p, sample9].transpose().collectEntries{ k1, k2, v -> ["${k1}${k2}", v] })
// -> [A1:555, B2:454, C3:678, D4:456]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.