A Vector
is a historical collection class that acts
like a growable array, but can store heterogeneous data elements.
With the Java 2 SDK, version 2, the Vector
class has
been retrofitted into the Collections Framework hierarchy to
implement the List
interface. However, if you are using
the new framework, you should use ArrayList
, instead.
When transitioning from Vector
to ArrayList
,
one key difference is that the arguments have been reversed to
positionally change an element's value:
- From original
Vector
class
void setElementAt(Object element, int index)
- From
List
interface
void set(int index, Object element)
The Stack
class extends Vector
to implement
a standard last-in-first-out (LIFO) stack, with push()
and pop()
methods. Be careful, though. Because the Stack
class extends the Vector
class, you can still access or
modify a Stack
with the inherited Vector
methods.