Win a copy of Microservices in Action this week in the Web Services forum!
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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Bear Bibeault
• Devaka Cooray
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Knute Snortum
• Junilu Lacar
• paul wheaton
Saloon Keepers:
• Ganesh Patekar
• Frits Walraven
• Tim Moores
• Ron McLeod
• Carey Brown
Bartenders:
• Stephan van Hulst
• salvin francis
• Tim Holloway

# Hunt # 49

Ranch Hand
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.
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
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
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

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
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
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
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
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

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.