繁体   English   中英

如何在Java中检查元素不为null

[英]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));
        }

现在我正在获取filterItems size = 1但该值为null。如何检查数组元素不等于null。

if(filterItems != null)
{

 code
}

但是这种情况不起作用...请帮助我。

尝试:

String s = (String) it.next();
if(s != null){
    filterItems.add(new SelectItem(s, s));
}

大概您从RefListMap获得的值是null。 您可能需要先检查s是否为null,然后再将其添加到filterItems

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM