2

I created a user defined variable i and put value 0. In groovy I try to run on a list starting [i], but it returned 48. when I hard coded put 0, the script is OK why I is set to 48?

List<String> myList = props.get("myListKey");
int i = vars.get("i"); 
String id = myList[i];
//String id = myList[0];
System.out.println("id:  " + id);
vars.putObject("id", id);
System.out.println("I is:  " + i);

enter image description here

enter image description here

enter image description here

user7294900
  • 52,490
  • 20
  • 92
  • 189
Bastian
  • 901
  • 4
  • 20
  • 52

1 Answers1

3

The correct way to convert String to number in groovy is using toInteger() function:

int value =  vars.get("i").toInteger()    
log.info("I2 is:  " + value);

Currently you return the ASCII value of character 0 (48). you can check also other options to convert String to int.

user7294900
  • 52,490
  • 20
  • 92
  • 189