Source of J4.6.java


  1: // @author Frank M. Carrano, Timothy M. Henry
  2: // @version 5.0
  3: ListInterface<String> nameList = new MyList<>();
  4: nameList.add("Jamie");
  5: nameList.add("Joey");
  6: nameList.add("Rachel");

  8: Iterator<String> nameIterator = nameList.iterator();

 10: nameIterator.hasNext() // Returns true because a next entry exists.
 11: nameIterator.next()    // Returns the string Jamie and advances the iterator.
 12: nameIterator.next()    // Returns the string Joey and advances the iterator.
 13: nameIterator.next()    // Returns the string Rachel and advances the iterator.
 14: nameIterator.hasNext() // Returns false because the iterator is beyond the end of the list.
 15: nameIterator.next()    // Causes a NoSuchElementException.