wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about VEctor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about VEctor" Watch "Question about VEctor" New topic
Author

Question about VEctor

Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
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

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

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Pratap Reddy
Ranch Hand

Joined: Jan 05, 2001
Posts: 36
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
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
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
Thanx Mr. Satya for ur help

Regards
Khurram
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
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://aspose.com/file-tools
 
subject: Question about VEctor