使用mvel检查List中是否存在元素 [英] Checking whether a element present in List using mvel
本文介绍了使用mvel检查List中是否存在元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个清单.列表就像.
I had a list with me. The list is like.
List<String> locations=new ArrayList<String>();
locations.add("California");
location.add("sydney");
location.add("Egypt");
现在,我想检查一下此列表是否包含加利福尼亚和悉尼.我以为我可以用下面的那一个,但这给出了错误.
Now I want to check in mvel whether this list contains California and Sydney. I thought I could use the below one but that is giving error.
location contains "sydney","california"
如何查找列表中是否包含mvel中的多个元素?
How can I find whether a list contains multiple elements in mvel?
推荐答案
这对我有用:
//@Test
public void testListContains() {
List<String> locations = new ArrayList<String>();
locations.add("California");
locations.add("sydney");
locations.add("Egypt");
String expression = "thelocations contains acity && thelocations contains anothercity";
Map container = new HashMap();
container.put("thelocations", locations);
container.put("acity", "sydney");
container.put("anothercity","California");
Object result = MVEL.eval(expression,container);
System.out.println(result);
}
这篇关于使用mvel检查List中是否存在元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文