[英]How to check element is not null in java
filterItems = null;
filterItems = new ArrayList<SelectItem>();
Iterator<String> it = RefListMap.keySet().iterator();
while (it.hasNext()) {
String s = (String) it.next();
filterItems.add(new SelectItem(s, s));
}
Now i am getting filterItems size=1 but that value is null.How to check array element is not equal to null. 现在我正在获取filterItems size = 1但该值为null。如何检查数组元素不等于null。
if(filterItems != null)
{
code
}
but this condition is not working...Please help me. 但是这种情况不起作用...请帮助我。
try: 尝试:
String s = (String) it.next();
if(s != null){
filterItems.add(new SelectItem(s, s));
}
Presumably the value you're getting from the RefListMap
is null. 大概您从RefListMap
获得的值是null。 You might check whether s
was null before you add it to filterItems
. 您可能需要先检查s
是否为null,然后再将其添加到filterItems
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.