I have three arraylist(int, string, and one more string) in one class. In the other class I the code that loops through all three it looks like this:
public class ArrayContainer<T> implements ArrayContainerInterface<T> {
private T[] container;
private int defaultSize = 25;
private int numItems;
public ArrayContainer() {
container = (T[]) new Object[defaultSize];
numItems =0;
}
@Override
public void add(T item) {
if (numItems < defaultSize)
{
container[++numItems] = item;
}
}
@Override
public boolean isFull() {
return false;
}
@Override
public String toString() {
String output = new String();
for (int i=0; i < defaultSize; i++) {
output += container[i];
}
return output;
}
}
the stack trace that i'm getting looks like this:
null01234567891011121314151617181920212223
The number container object is NOT full!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 25
at ArrayContainer.add(ArrayContainer.java:17)
at ArrayContainerDriver.main(ArrayContainerDriver.java:31)
what exactly is wrong with my code that is giving me an error like this?
The link to my GitHub and to the rest of my classes are here