使用Jasper变量作为Arrays.asList()的参数。

huangapple go评论93阅读模式
英文:

Use a Jasper variable for Arrays.asList() argument

问题

我想拆分参数的内容,然后使用.contains()方法,如下所示:

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

并且我想将内容放入asList()中的一个不同变量,使其看起来像这样:

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

但我遇到了一个错误:

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

我的变量应该是什么类型?我尝试了String、Collection、ArrayList,但都不起作用。

英文:

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.

答案1

得分: 0

我只是将以下内容放入新变量中,并将其类型设置为List

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

现在我可以像这样使用它

$V{namesArray}.contains($F{name})
英文:

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})

huangapple
  • 本文由 发表于 2023年8月9日 15:27:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865495-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定