将int数组的字符串表示形式转换为groovy列表

iCo*_*ode 3 groovy

如果给我一个字符串,这是一个int数组的代表,如下所示

String d = "[2,3,4,5]"

我如何转换为字符串数组?

String[] f = convert d to array of String

另外我如何转换为int数组?

int[] f = convert d to array of int
Run Code Online (Sandbox Code Playgroud)

Sto*_*nov 7

我正在寻找其他解决方案,因为我的值包含字符串,包括其中的点,并找到了这个.

此代码应该适合您:

"[1,2,3]".tokenize(',[]')*.toInteger()
Run Code Online (Sandbox Code Playgroud)