How to instantiate arrays immediately with set values


In java language its posisble to instantiate arrays immediately with values on the same line using the {} format: For example, I tried this…

String[] test = new String[] {"a", "b", "c"}

But when I try it in Katalon I get an error


Is there a way around this or is it a limitation of Groovy and I just have to set each value of the String individually, ex… test[0] = “a”, etc. ?


You are so close. Try :

String[] test = ["a", "b", "c"]

Groovy initialization of array of objects - Stack Overflow

1 Like

side note, in groovy you don’t have array, but mostly lists and maps
ok, are wrappers, however please decide between using java or groovy

String[] test = ["a", "b", "c"]

this is not groovy

1 Like

This works!