This week's book giveaway is in the Kotlin forum.We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Adding an element in a Vector... ???

Anonymous
Ranch Hand
Posts: 18944
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.
What should be the answer for the above. One of the Mock Exam says that it should be C. But I feel it should be B. Since JLS says that 2nd argument is the "capacityIncrement - the amount by which the capacity is increased when the vector overflows."
Thanks & Regards.

Anonymous
Ranch Hand
Posts: 18944
import java.util.*;
public class Class1 {
public static void main(String args[]) {
Vector v = new Vector(5, 10);
System.out.println(v.capacity());
System.out.println(v.capacity());
}
}
Output :
5
15
Vector v = new Vector(5, 10); indicates -
Create a vector with initial capacity of 5
When it become full increase the capacity by 10 i.e 5 + 10.
Let me know if I'm wrong.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.