Java Reference
In-Depth Information
public void
ensureCapacity(
int
newCapacity)
Increases the capacity of the calling vector to ensure that it can hold at least
newCapacity
elements. Using
ensureCapacity
can sometimes increase effi ciency, but its use is not needed
for any other reason.
public void
setSize(
int
newSize)
Sets the size of the calling vector to
newSize
. If
newSize
is greater than the current size, the
new elements receive the value
null
. If
newSize
is less than the current size, all elements at
index
newSize
and greater are discarded.
Throws:
ArrayIndexOutOfBoundsException
if
newSize
is negative.
public int
size()
Returns the number of elements in the calling vector.
public void
trimToSize()
Trims the capacity of the calling vector to be the vector's current size. This is used to save storage.
MAKE A COPY
public
Object clone()
Returns a clone of the calling vector. The clone is an identical copy of the calling vector.
OLDER METHODS
These are methods that are not part of the newer collection framework, but are retained for
backward compatibility. You should use the previously described newer methods instead. But,
you may fi nd these used in older code.
public void
addElement(T newElement)
Same as
add
.
public void
insertElementAt(T newElement,
int
index)
Same as
add
.
public
T elementAt(
int
index)
Same as
get
.
public void
removeAllElements()
Same as
clear
.
public boolean
removeElement(Object theElement)
Same as
remove
.