@Override public boolean hasNext() { boolean matchFound = false; while (ec.hasMoreElements()) { Candidate tempObj = (Candidate) ec.nextElement(); if (tempObj.getCertificationType().equals(certifiedcationType)) { matchFound = true; nextCandidate = tempObj; break; } if (matchFound == true) { } else { nextCandidate = null; } } return matchFound; }