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
• Liutauras Vilda
• Bear Bibeault
• Paul Clapham
• Jeanne Boyarsky
Sheriffs:
• Devaka Cooray
• Junilu Lacar
• Tim Cooke
Saloon Keepers:
• Tim Moores
• Ron McLeod
• Tim Holloway
• Claude Moore
• Stephan van Hulst
Bartenders:
• Winston Gutkowski
• Carey Brown
• Frits Walraven

# vector question HUNT

Ranch Hand
Posts: 232
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
//I REALLY DONT KNOW WHAT IS GOING ON HERE

Ranch Hand
Posts: 158

Sarim,
First parameter is initial capacity the second one is the capacity increment value. This denotes by how many elements the capacity is increased when the vector overflows. The answer is obvious now. Isnt it?
Rgds
Sahir
[This message has been edited by Sahir Shah (edited December 21, 2000).]

Ranch Hand
Posts: 1070
This question is asking about the constructor for the Vector class. Easiest thing to do then is look it up in the API.
The constructor says:

Vector (int initialCapacity, int capacityIncrement)

So you know it starts with 5 and will increase by 10. Now the next question is when does it increase to 10, when you add the 5th element or the 6th element. Again look at the API:

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

So it will increase when it overflows, which makes sense from a efficiency standpoint. That means when the 6th element is added, it will increase 10 more elements making C the correct answer as it will now have 15 elements.
Bill

Ranch Hand
Posts: 81
try this code and see
import java.util.Vector;
class A {
public static void main(String args[])
{
int i,j;
Vector v = new Vector(5,10);
for (int l = 1;l<8 ;++l ){