Class ArrayIterator<ElementType>

java.lang.Object
com.Ostermiller.util.ArrayIterator<ElementType>
Type Parameters:
ElementType - Type of array over which to iterate
All Implemented Interfaces:
Iterator<ElementType>

public class ArrayIterator<ElementType> extends Object implements Iterator<ElementType>
Converts an array to an iterator.

More information about this class is available from ostermiller.org.

Since:
ostermillerutils 1.03.00
Author:
Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an Iterator from an Array.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tests if this Iterator contains more elements.
    Returns the next element of this Iterator if this Iterator object has at least one more element to provide.
    void
    Removes the last object from the array by setting the slot in the array to null.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Constructor Details

    • ArrayIterator

      public ArrayIterator(ElementType[] array)
      Create an Iterator from an Array.
      Parameters:
      array - of objects on which to enumerate.
      Since:
      ostermillerutils 1.03.00
  • Method Details

    • hasNext

      public boolean hasNext()
      Tests if this Iterator contains more elements.
      Specified by:
      hasNext in interface Iterator<ElementType>
      Returns:
      true if and only if this Iterator object contains at least one more element to provide; false otherwise.
      Since:
      ostermillerutils 1.03.00
    • next

      public ElementType next() throws NoSuchElementException
      Returns the next element of this Iterator if this Iterator object has at least one more element to provide.
      Specified by:
      next in interface Iterator<ElementType>
      Returns:
      the next element of this Iterator.
      Throws:
      NoSuchElementException - if no more elements exist.
      Since:
      ostermillerutils 1.03.00
    • remove

      public void remove()
      Removes the last object from the array by setting the slot in the array to null. This method can be called only once per call to next.
      Specified by:
      remove in interface Iterator<ElementType>
      Throws:
      IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
      Since:
      ostermillerutils 1.03.00