while (iterator.hasNext()) { Map.Entry pairs = (Map.Entry)iterator.next(); Notification message = (Notification) pairs.getValue(); if(null!=message && null!=message.getDescription() && null!=notificationSearchCriteria.getDescription() ) { //Do your comparioson }else{ //Handle the NullPointerException error the way you want } }