英文:
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})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论