# Vectors

Shafeeq Sheikh

Ranch Hand

Posts: 68

posted 15 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 of 10 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 given answer is C. But according to the JLS:

So shouldn't the answer be B.???

Thanks in advance....

new Vector(5, 10);

A) An IndexOutOfBounds exception is raised.

B) The vector grows in size to a capacity of 10 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 given answer is C. But according to the JLS:

**public Vector(int initialCapacity, int capacityIncrement)**

Constructs an empty vector with the specified initial capacity and capacity increment.

initialCapacity - the initial capacity of the vector.

capacityIncrement - the amount by which the capacity is increased when the vector overflows.Constructs an empty vector with the specified initial capacity and capacity increment.

initialCapacity - the initial capacity of the vector.

capacityIncrement - the amount by which the capacity is increased when the vector overflows.

So shouldn't the answer be B.???

Thanks in advance....

Mohan Ramanna

Ranch Hand

Posts: 36

deekasha gunwant

Ranch Hand

Posts: 396

posted 15 years ago

hi shafeeque,

u ur self have answered ur question.

--------------------------------------------------

in this case

initial capacity = 5

adding 6th element ------> overflow

so according to JLS increase the capacity by 10.

hence new capacity = 5+ 10 = 15

----------------------------------------------------

& that's why C is the correct answer

regards

deekasha

Thanks in advance....

[/B]

u ur self have answered ur question.

**public Vector(int initialCapacity, int capacityIncrement)**

Constructs an empty vector with the specified initial capacity and capacity increment.

initialCapacity - the initial capacity of the vector.

capacityIncrement - the amount by which the capacity is increased when the vector overflows.Constructs an empty vector with the specified initial capacity and capacity increment.

initialCapacity - the initial capacity of the vector.

capacityIncrement - the amount by which the capacity is increased when the vector overflows.

--------------------------------------------------

in this case

initial capacity = 5

adding 6th element ------> overflow

so according to JLS increase the capacity by 10.

hence new capacity = 5+ 10 = 15

----------------------------------------------------

& that's why C is the correct answer

regards

deekasha

Thanks in advance....

[/B]

Consider Paul's rocket mass heater. |