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

posted

0

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).]

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

posted

0

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

posted

0

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

posted

0

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.

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

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