HI guyz , What is the size of a vector ? we can access its elements by passing an integer as an argument so , is size of the vector equal to maximum integer value ? dont hesitate to reply , just write whatever is in all of ur minds regards Khurram Fakhar
Vector defines two methods size() and capacity(). Size give number of you already stored and capacity() gives maximum number of objects can be stored.
Joined: May 29, 2000
Hi ppl, Well mr. Satya , i have already read the documentation but there is no material regarding my question. My question was, what is the maximum size of a vector. We ppl access elements of vectors by passing an integer value. An integer has some specific limit to store some value. So what if , elements in vector exceeds more than that limit of integer value ? how can we access those elements which cant be accessed by passing integer argument ? Correct me if i m wrong .
Regards Khurram Fakhar
Joined: Jun 03, 2000
So what if , elements in vector exceeds more than that limit of integer value ? how can we access those elements which cant be accessed by passing integer argument Forgive me, my imagination is limited But, don't you think that an Exception of some kind will be thrown when vector exceeds more than that limit of integer value. I would guess thats what will happen. Hope I got you right this time. Regds. - satya
A Vector is backed by an array. Since the dimension of an array is of type int, the capacity of a Vector (and thus its size too, since size <= capacity) is be at most Integer.MAX_VALUE.
If a Vector v already has the maximum size, then attempting to addElement() will cause the following:
The new size-to-be will be considered to be Integer.MAX_VALUE + 1, i.e. Integer.MIN_VALUE
This being negative, hence smaller than the current capacity will result in a request to ensure capacity not to be made
An attempt to add the element will still be made (to position Integer.MIN_VALUE in the array). Integer.MIN_VALUE being negative, this will result in an ArrayIndexOutOfBoundsException. Hope this helps, Panagiotis. [This message has been edited by Panagiotis Varlagas (edited January 10, 2001).]