开发者

How to check element is not null in java

开发者 https://www.devze.com 2023-01-16 22:34 出处:网络
filterItems = null; filterItems = new ArrayList<SelectItem>(); Iterator<String> it = RefListMap.keySet().iterator();
filterItems = null;
filterItems = new ArrayList<SelectItem>();


Iterator<String> it = RefListMap.keySet().iterator();
        while (it.hasNext()) {
            String s = (String) it.next();
        开发者_如何学Go    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.

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. You might check whether s was null before you add it to filterItems.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号