The capacity() method tells you have many elements the Vector can take, before it has to increase its capacity. It doesn t tell you have many elements that currently is in the Vector, that s what size() is assigned to do. And in your case it does, since the Vector is empty.
You can specify the capacity by providing parameters to the constructor:
Vector v = new Vector(20);
/* This vector will have the starting capacity
of 20 elements, before it has to increase
its capacity */
Vector v = new Vector(10, 5);
/* This vector will have an initial capacity
of 10 elements, and when it overflows the
second parameter tells the vector to increase
its capacity by 5. */
Edit
Based on your comments to other posts, it seems that you have two threads in your application - where one puts stuff into the vector and another one reads the vector?
Then you have to add a control structure to check wether the vector is empty or not, before trying to get elements from it.
Dirty example:
/* Vector instantiation goes here */
boolean keepRunningFlag = true;
while(keepRunningFlag) {
if (!vector.isEmpty()) {
Object o = vector.remove(vector.size() - 1);
keepRunningFlag = doStuffWithVectorElement(o);
}
}