Jmeter: How to use ArrayList in Jmeter, Beanshell Sampler?

Das Prakash picture Das Prakash · Aug 17, 2016 · Viewed 9.2k times · Source

How to use Array list in Beanshell Sampler-Jmeter?

Answer

Dmitri T picture Dmitri T · Aug 18, 2016

Just like in Java, i.e. the following code:

ArrayList myList = new ArrayList();
myList.add("something");
myList.add("something else");

for (int i = 0; i < myList.size(); i++) {
  log.info(myList.get(i));
}

Will print myList contents to jmeter.log file:

Beanshell ArrayList


Remember that Beanshell doesn't support Generics so avoid using diamond operators elsewise you'll get errors. If there is no particular reason for sticking to Beanshell I would suggest considering switching to JSR223 Test Elements and Groovy language - see Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for explanation, benchmarks and scripting best practices.