Search code examples
javastringlistgroovy

Convert String variable to a List [Groovy]


How can I convert this String variable to a List ?

def ids = "[10, 1, 9]"

I tried with: as List and toList();


Solution

  • def l = Eval.me(ids)
    

    Takes the string of groovy code (in this case "[10,1,9]") and evaluates it as groovy. This will give you a list of 3 ints.