Source of JI5.6.java


  1: // Version 4.0
  2: ListInterface<String> nameList = new LList<>();
  3: nameList.add("Jamie");
  4: nameList.add("Joey");
  5: nameList.add("Rachel");
  6: 
  7: Iterator<String> nameIterator = nameList.iterator();
  8: 
  9: nameIterator.hasNext() // Returns true because a next entry exists.
 10: nameIterator.next()    // Returns the string Jamie and advances the iterator.
 11: nameIterator.next()    // Returns the string Joey and advances the iterator.
 12: nameIterator.next()    // Returns the string Rachel and advances the iterator.
 13: nameIterator.hasNext() // Returns false because the iterator is beyond the end of the list.
 14: nameIterator.next()    // Causes a NoSuchElementException.