collections-ArrayList
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   MAHEMED_RAFIUDDIN
Posted On:   Saturday, July 23, 2005 09:47 AM

we say that ArrayList is growable and Array is not.

what my question is:

what is the internal process of the JVM to increase the
size of the ArrayList?


Please use html tags to format code blocks.

Re: collections-ArrayList

Posted By:   Almagest_FUTT  
Posted On:   Saturday, July 23, 2005 11:06 AM


/**
* Increases the capacity of this ArrayList instance, if
* necessary, to ensure that it can hold at least the number of elements
* specified by the minimum capacity argument.
*
* @param minCapacity the desired minimum capacity.
*/
public void ensureCapacity(int minCapacity) {
modCount++;
int oldCapacity = elementData.length;
if (minCapacity > oldCapacity) {
Object oldData[] = elementData;
int newCapacity = (oldCapacity * 3)/2 + 1;
if (newCapacity < minCapacity)
newCapacity = minCapacity;
elementData = new Object[newCapacity];
System.arraycopy(oldData, 0, elementData, 0, size);
}
}
About | Sitemap | Contact