This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HELP ME

 
rajani adapa
Ranch Hand
Posts: 54
  • 0
  • 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);

An IndexOutOfBounds exception is raised.
The vector grows in size to a capacity of 10 elements
The vector grows in size to a capacity of 15 elements
Nothing, the vector will have grown when the fifth element was added
Select the most appropriate answer.

can anyone tell me what is the answer and why?
 
Peter Tran
Bartender
Posts: 783
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ans: The vector grows in size to a capacity of 15 elements.
For Vector, the c'tor you're invoking is:

Initial capacity = 5
capacityIncrement = 10
When you added the 6th element, the Vector had to resize. It will add 10 to the current size (5) which gives 15.
-Peter

[This message has been edited by Peter Tran (edited January 26, 2001).]
 
Val Dra
Ranch Hand
Posts: 439
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the answer i believe is
The vector grows in size to a capacity of 15 elements
because the inital was 5 so whenever you go over it , it will be increased to 15 i think that if you go over that , the capacity will be increased proportionaly .
 
rajani adapa
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u guys .
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic