Reputation: 354
Below is my code.
package findDuplicatre;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class FindDuplicate {
public static void main(String[] args) {
String[] ContentNameCount = {"name1","name1","name2","name2", "name2"};
List<String> sampleList = (List<String>) Arrays.asList(ContentNameCount);
for(String inpt:ContentNameCount){
int frequency=Collections.frequency(sampleList,inpt);
log.error(inpt+" "+frequency); //System.out.println(inpt+" "+frequency);
}
}
}
In eclipse i could get results:
name1 2
name1 2
name2 3
name2 3
name2 3
When i could run the same code in Eclipse without any error.But when i run the same code in jmeter beanshell sampler i'm getting below errors.
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``package findDuplicatre; import java.util.*; import java.util.Collections; impor . . . '' Encountered "=" at line 13, column 41.
Can anyone kindly explain me what am i missing and how would it make difference when i run in beanshell script.
Upvotes: 0
Views: 2077
Reputation: 58782
@Dmitri T answer is valid, you can still overcome the exception (remove diamond operators) in Beanshell:
String[] sampleList = {"name1","name1","name2","name2", "name2"};
for(String inpt:sampleList){
int frequency=Collections.frequency(Arrays.asList(sampleList),inpt);
log.error(inpt+" "+frequency); //System.out.println(inpt+" "+frequency);
}
Upvotes: 0
Reputation: 168092
Beanshell is not Java, you need to stick to Java SE 1.5 language features in general. In particular your case you need to remove diamond operators from your code as they were introduced in Java 7 and Beanshell doesn't support them like:
List sampleList = Arrays.asList(ContentNameCount);
A better option would be going for JSR223 Test Elements and Groovy language. Groovy is compatible with all modern Java language features, moreover it has much better performance comparing to Beanshell. See Apache Groovy - Why and How You Should Use It for more details.
Upvotes: 1