简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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