aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Hunt # 49 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Hunt # 49" Watch "Hunt # 49" New topic
Author

Hunt # 49

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
what is the effect of adding the sixth element to a vector created in the following manner?
new Vector(5, 10);
A. An IndexOutOfBounds exception is raised.
B. The vector grows in size to a capacity of10 elements
C. The vector grows in size to a capacity of 15 elements
D. Nothing, the vector will have grown when the fifth element was added.
the answer is C.
Can someone explain more specific about the two agrs of the vector instance, what they represent to, please?
rgds,
LeClair
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
As specified in Java 1.2 API:
(http://java.sun.com/products/jdk/1.2/docs/api/java/util/Vector.html#constructor_detail)
Vector
public Vector(int initialCapacity,
int capacityIncrement)
Constructs an empty vector with the specified initial
capacity and capacity increment.
Parameters:
initialCapacity - the initial capacity of the vector.
capacityIncrement - the amount by which the capacity is
increased when the vector overflows.
Throws:
IllegalArgumentException - if the specified initial
capacity is negative

Accordingly, the answer will be C.
(The vector size will be 5 + 10 = 15.)
Hope this helps.
Regds.
- satya

[This message has been edited by satya5 (edited May 02, 2000).]
sunny
Greenhorn

Joined: Feb 01, 2001
Posts: 23
I think the answer is B.
New Vector(5,10) means vector is created with initial capacity of 5 elements and then it grows in size of 10.
Leclair, would you please check your answer and let us know? I just need to verify that I am not missing something here.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

sunny:
the final capacity of the vector is 5 + 10 which is 15,
Answer C.
(we are not talking of how much increment, we are talking
about the final capacity of the vector.)
Regds.
- satya
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Sunny, I check it again, the answer is C. And I think satya5 has showed the explaination very clearly. Thank you, appreciate.
LeClair
sunny
Greenhorn

Joined: Feb 01, 2001
Posts: 23
Oh Yeah. I had to read the question again. What is the EFFECT of adding the sixth element? Surely, vector grows in size to a capacity of 15 elements.
Answer is C.
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234
initially the vector is of capacity 5
now when this capactiy is filled up i.e. when we are adding the sixth element, the vector will grow by 10 in addition ot the already existing 5
which makes a total capacity of 15

sona<br />SCJP
Richard Scothern
Ranch Hand

Joined: May 25, 2001
Posts: 83
The second argument of the vector constructor is the length the vector grows by when it becomes full.
So the vector grows by an amount of 10 from 5. 15.
If you don't include a second argument the vector length doubles.
Richard
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hunt # 49