ap.java.util
Class NoSuchElementException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
ap.java.util.NoSuchElementException
- All Implemented Interfaces:
- java.io.Serializable
- public class NoSuchElementException
- extends java.lang.RuntimeException
Students should understand this error/exception
when it occurs in a program.
An object of this class is thrown when a collection or iterator
is empty. For example, when the
next
method of an Iterator
instance is
called when hasNext
of that instance returns
false
as in the code below.
ArrayList list = new ArrayList();
list.add(new String("hello"));
Iterator it = list.iterator();
System.out.println(it.next()); // ok, list has one element
System.out.println(it.next()); // NOT ok, iterator is "empty"
AB students are expected to be able to throw this exception in code
they write.
- See Also:
- Serialized Form
Methods inherited from class java.lang.Throwable |
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
NoSuchElementException
public NoSuchElementException()