Java – NoSuchElementException

NoSuchElementException: Thrown when one tries to access an element that is not present, such as an empty iterator.
Example:

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

No images available.