programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# Hunt # 49

Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
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.
Can someone explain more specific about the two agrs of the vector instance, what they represent to, please?
rgds,
LeClair

Anonymous
Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
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).]

Greenhorn
Posts: 23
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:

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

Anonymous
Ranch Hand
Posts: 18944
• Number of slices to send:
Optional 'thank-you' note:
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
Posts: 23
• Number of slices to send:
Optional 'thank-you' note:
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.

Ranch Hand
Posts: 234
• Number of slices to send:
Optional 'thank-you' note:
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

Ranch Hand
Posts: 83
• Number of slices to send:
Optional 'thank-you' note:
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

 this is supposed to be a surprise, but it smells like a tiny ad: Free, earth friendly heat - from the CodeRanch trailboss https://www.kickstarter.com/projects/paulwheaton/free-heat