posted 18 years ago

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

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

Posts: 18944

posted 18 years ago

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

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

posted 18 years ago

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.

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

posted 18 years ago

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

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

Posts: 18944

posted 18 years ago

Sunny, I check it again, the answer is C. And I think satya5 has showed the explaination very clearly. Thank you, appreciate.

LeClair

LeClair

sunny

Greenhorn

Posts: 23

posted 18 years ago

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.

Answer is C.

posted 17 years ago

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

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

posted 17 years ago

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

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