This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

vector question HUNT  RSS feed

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ){
v.addElement(new Integer(5));
i = v.size();
j = v.capacity();
System.out.println("element no " +l +" size= " + i+ " capacity = "+j );}
//c = b
}
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!