I'm using a Stack
in Java. The problem is that I only can push 10 items into the stack, and I need to push 20 items.
How do I increment the capacity of the stack?
I'm using a Stack
in Java. The problem is that I only can push 10 items into the stack, and I need to push 20 items.
How do I increment the capacity of the stack?
The Java 7 Stack is not bound to any size. It is back by a Vector which says it is a "a growable array of objects".
You should be able to add as many object to the Stack as you like.
Stack
extendsVector
which has a constructor that defines an initial capacity. There's also a method calledensureCapacity(int minCapacity)
which could help youbut as the other posters said: you shouldn't have to do this manually. Maybe providing some code snippets could enlighten us all.
Java's
Stack
class inherits fromVector
and provides convenience methods to allow aVector
to behave like a stack. SinceVector
grows naturally, there's no need to increase the capacity manually.I'm guessing you're doing something else wrong. That, or I misunderstood your question. If you want a more accurate answer, please give more information, such as the code your using, what behavior are you expecting, what behavior are you getting, etc.