Name
java.util.Vector
Synopsis
This class is a scaled-down version of the J2SE
Vector class. The class represents a dynamic array
that can grow and shrink as necessary. A vector starts with an array
of a preset capacity, set either through the constructor or the
ensureCapacity() method, and increases the size if
needed. Elements can be added to the vector using the
addElement() method. The
indexOf() method can be used to obtain the index
of a desired element in the array, which can be removed using the
elementAt() method. Note that the object returned
is simply an Object; be sure to recast it to the
appropriate type. You can remove elements using the
removeElement() and
removeElementAt() methods.
size() returns the size of the element array.
trimToSize() reduces the size of the
vector’s array to match the current number of elements.
public classVector{ // protected fields protected intcapacityIncrement; protected intelementCount; protected Object[]elementData; // constructors publicVector(); publicVector(int initialCapacity); publicVector(int initialCapacity, int capacityIncrement); // public instance methods public synchronized voidaddElement(Object obj); public intcapacity(); public booleancontains(Object elem); public synchronized voidcopyInto(Object[] anArray); public synchronized ObjectelementAt(int index); public synchronized Enumerationelements(); public synchronized voidensureCapacity(int minCapacity); public synchronized ObjectfirstElement(); public intindexOf ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access