Java Reference
In-Depth Information
No analogue. If
newSize
is less than the current size, extra
data is dropped. If
newSize
is larger than the current size, any
added elements are
null
.
public final int
capacity()
No analogue. Returns the current capacity of the vector.
In addition to these public methods, protected fields are available to
classes that subclass the
Vector
class. Be careful what you do (if any-
thing) with these fields because, for example, methods in
Vector
rely on
elementCount
being less than or equal to the length of the
elementData
ar-
ray.
protected Object[]
elementData
The buffer where elements are stored.
protected int
elementCount
The number of elements currently used in the buffer.
protected int
capacityIncrement
The number of elements to add to the capacity when
ele-
mentData
runs out of space. If zero, the size of the buffer is
doubled every time it needs to grow.
21.15.3.
Stack
The
Stack<E>
class extends
Vector<E>
to add methods for a simple last-
in-first-out stack of objects. Use
push
to push an object onto the stack
and use
pop
to remove the top element from the stack. The
peek
method
returns the top item on the stack without removing it. The
empty
method
returns
TRue
if the stack is empty. Trying to
pop
or
peek
in an empty
Stack
object will throw an
EmptyStackException
.