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
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
Pl. refer to the Java API specs for the Vector class. Hope this answers most of the qstns. I hate to miss something which you need to know. Regds. - satya
Vector defines two methods size() and capacity(). Size give number of you already stored and capacity() gives maximum number of objects can be stored.
Khurram Fakhar
Ranch Hand
Joined: May 29, 2000
Posts: 65
posted
0
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
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
posted
0
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
Khurram Fakhar
Ranch Hand
Joined: May 29, 2000
Posts: 65
posted
0
Thanx Mr. Satya for ur help Regards Khurram
Panagiotis Varlagas
Ranch Hand
Joined: Nov 27, 2000
Posts: 233
posted
0
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).]
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.