what is the default value of Vector?
what is the default value of the Vector? now another main thing i have generate one vector with fix size like
Vector v=new Vector(5);
now the thing is that suppose i add sixth element at that time it's size will be 10 or will be 15.
Vector v1=new Vector(15);
now i add 16 the elment so at that time vector size is 25 or it will be 30?
what do you mean default value?Vector v1 = new Vector(5);creates a new vector of size 0 not 5.size returns the number of objects in the vector not the ensured minimum capacity
default value means it's incremental factor, r u get my point
when i define vector
Vector v=new Vector(5)
at that time it's size is differenct and when i add 6th element at that time also it's size will be changed so i wan't to know when i add six element at that time it size will be double or it will be add default incremental factor to the size?
Vector v = new Vector();
intitial internal array size is 10. capacityIncrement = 0
These are automatically(meaning we do not normally care how) changed as you add the data.
If it is important to you to know internal array size of the vector
then use
Vector v = new Vector(int initialCapacity, int capacityIncrement);
ya friend u r right in this way but my problem is that
Vector v=new Vector(5)
ok now i already add 5 elements and now i add sixth element right at that time it allows me to add sixth element because it is growable right but my problem is that u say it's default size is 10 right,i mentioned in above examples 5 ,so it's current size is 5 and now i add the new element so at that time it's size is 10 or 15 i confuse in this point
r u get my point?
"public Vector (int initialCapacity, int capacityIncrements);
begins with initialCapacity
if/when it needs to grow, it grows by size capacityIncrements
public Vector (int initialCapacity);
begins with initialCapacity
if/when needs to grow, it grows by doubling current size.
public Vector( );
begins with capacity of 10
if/when needs to grow, it grows by doubling current size.
"
ya i get it your point let's i explain which i understand from your side ok
Vector v=new Vector(10,15)
so in this case it's size is 10 right when i add 11the element at that time it's size is 25 right?
Vector v1=new Vector(5);
in this case the it's size is 5 right and when i add 6th element at that time it's size will be double in short 10 in this case right.
Vector v2=new Vector();
in this case the default size is 10 right when i add 11th element at that time it's size is 20 right
If my understanding is wrong then pl'z explain this thing with examples
waiting for your reply.
No. Those parameters you're providing specify the capacity of the Vector. That's how many elements it could contain without having to resize, not how many it does contain. Initially a Vector contains zero elements. The Vector will resize when the number of elements in it exceeds its capacity.
But you shouldn't be using a Vector anyway, it has been obsolete for about 5 years now. Use an ArrayList. Especially if this capacity business is too complicated for you to understand.