Java – NoSuchElementException

NoSuchElementException: Thrown when one tries to access an element that isn’t present.
Example:

import java.util.Iterator;
import java.util.NoSuchElementException;
Iterator iterator = new ArrayList().iterator();
try {
iterator.next();
} catch (NoSuchElementException e) {
System.out.println("Caught NoSuchElementException: " + e.getMessage());
}

No images available.