Search code examples
jasper-reports

Use a Jasper variable for Arrays.asList() argument


I want to split the content of a parameter and then use the .contains() method like so

Arrays.asList($P{names}.trim().split("\\s*,\\s*")).contains($F{name})

And I want to put the content in asList() in a differenet variable so that it looks like this

Arrays.asList($V{namesArray}).contains($F{name})

But I get an arror

Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String

What should the type of my variable be? I tried with String, Collection, ArrayList but nothing works.


Solution

  • I just put the following thing in the new variable and made its type List

    Arrays.asList($P{names}.trim().split("\\s*,\\s*"))
    

    Now I can just use it like this

    $V{namesArray}.contains($F{name})