I have an array of objects in a class, call it passengers. I initialized the array with the x number of passengers, and that would make the array with length x, full of nulls. I need to get a method from the class where I can substitute the next null value for an object. What I'm doing right now is running through the whole array with a for loop and finding the first null value, then changing it to the object.
if(passenger == null){
// add a new passenger to this position in the array
}
}
What I was wondering is if is there any built-in method that would make this faster, where I could just substitute the next null value in an array, for a value. At the moment, I'm using Java 7, so there might be a Java 8 option, but it wouldn't work in my case.