I have the following Java
class that adds a Person object to an existing Person Array
:
public class PersonService{
protected int lastItemInPersonArray = 0;
private Person[] persons = new Person[100];
public void addPersonToPersonArray(Person personToAdd){
persons[lastItemInPersonArray++] = personToAdd;
}
}
I can add 1 object correctly here but when I try to 2 I get the following error:
java.lang.ArrayIndexOutOfBoundsException: 1
What is incorrect with my logic that is causing this?