X790: ArrayBag Clear

For this exercise, you are writing code in the following implementation of ArrayBag:

public static final class ArrayBag<T> implements BagInterface<T> {
    private T[] contents;
    private static final int MAX = 25;
    private int numberOfEntries;

    public ArrayBag() {
        T[] tempBag = (T[])new Object[MAX];
        contents = tempBag;
        numberOfEntries = 0;
    }
  }

Implement the remove() and clear() methods of a fixed size array bag. When calling remove, be sure to set the value in the underlying array to null. You will have access to isEmpty, but no other member methods of the Bag Interface when writing your code.

If the bag is already empty and remove is called, return null

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.