I'm doing some research into the ArrayList class as part of a school project.
In the Java API docs at Oracle's site, it mentions that all operations except a given few are "roughly linear time."
The constructors are not listed as part of the given few, but I'm having a hard time seeing how this:
public ArrayList(int initialCapacity) {
if (initialCapacity > 0) {
this.elementData = new Object[initialCapacity];
} else if (initialCapacity == 0) {
this.elementData = EMPTY_ELEMENTDATA;
} else {
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
}
}
is linear time. Am I missing something here?