APCS Java Subset

ap.java.util
Class NoSuchElementException

java.lang.Object
  extended byjava.lang.Throwable
      extended byjava.lang.Exception
          extended byjava.lang.RuntimeException
              extended byap.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

Constructor Summary
NoSuchElementException()
           
 
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
 

Constructor Detail

NoSuchElementException

public NoSuchElementException()

unofficial documentation for the APCS Java Subset