Class StaticArray<Item>

java.lang.Object
dsa.lab02.solutions.StaticArray<Item>
Type Parameters:
Item - the item type
All Implemented Interfaces:
Container<Item>, DynamicSequence<Item>, StaticSequence<Item>, Iterable<Item>

public class StaticArray<Item> extends Object implements DynamicSequence<Item>
A static array.

A dynamic sequence implemented using a full array (i.e. with as many items as slots).

Dynamic operations always reallocate a new array and are all O(n) (where n is the size).

  • Constructor Details

    • StaticArray

      public StaticArray()
      Construct an empty static array.
    • StaticArray

      public StaticArray(Iterable<Item> items)
      Construct a static array containing the given items.
      Parameters:
      items - the items
    • StaticArray

      public StaticArray(Iterable<Item> items, int size) throws IllegalArgumentException
      Construct a static array containing the given items more efficiently than StaticArray(Iterable).
      Parameters:
      items - the items
      size - the number of items
      Throws:
      IllegalArgumentException - if size != n (where n is items's size)
    • StaticArray

      @SafeVarargs public StaticArray(Item... items)
      Construct a static array containing the given items.
      Parameters:
      items - the items
  • Method Details