2010-09-19 44 views
1
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。如何檢查java中的元素不爲空

if(filterItems != null) 
{ 

code 
} 

但這種情況不起作用...請幫助我。

回答

4

嘗試:

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

想必你從RefListMap所獲得的價值是零。在將其添加到filterItems之前,您可能會檢查s是否爲空。