簡體   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