| | I've been studying for the AP CS test and just read that ArrayLists add objects in constant time, which I don't really get. Why would ArrayLists add in constant time when it needs to copy all of the objects in the array to a new array just to allocate a new space for the new object? Wouldn't that mean the ArrayList would run in O(n) time? The only explanation I can come up with is if the ArrayList doesn't change the array right away and instead puts the add function onto some sort of stack and waits until it gets numerous add functions and then performs all the add functions so that it only needs to create a new array once per x number of add functions. I'm rather confused, so any help would be appreciated. |

