Package utilities

Class MyArrayList.MyIterator<E>

java.lang.Object
utilities.MyArrayList.MyIterator<E>
Type Parameters:
E - The type of elements in this list.
All Implemented Interfaces:
Iterator<E>
Enclosing class:
MyArrayList<E>

private static class MyArrayList.MyIterator<E> extends Object implements Iterator<E>
A custom Iterator implementation for MyArrayList.
  • Field Details

    • list

      private MyArrayList<E> list
    • currentIndex

      private int currentIndex
  • Constructor Details

  • Method Details

    • hasNext

      public boolean hasNext()
      Description copied from interface: Iterator
      Returns true if the iteration has more elements. (In other words, returns true if next() would return an element rather than throwing an exception.)
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      true if the iterator has more elements.
    • next

      public E next() throws NoSuchElementException
      Description copied from interface: Iterator
      Returns the next element in the iteration.
      Specified by:
      next in interface Iterator<E>
      Returns:
      The next element in the iteration.
      Throws:
      NoSuchElementException - If the iteration has no more elements.