Vector: Vector Transactions New Vector
Vector: Vector Transactions New Vector
TrySimpleVecto
r.java
Storing Objects in a
Adds a reference to the object aName to
transactions.add(aName);
the Vector<> object called names.
New entry is added at the end of the
existing objects in the vector.
Vector size increases by 1.
All objects already stored in the vector
remain at their previous index position.
names.add(2, aName);
Inserts object aName as the 3rd entry of names
Returns
names.set(2, newName);
a reference to the object that was previously stored
at this position. This gives us a chance to hang on to the
displaced object if we want to keep it.
Changes the 3rd element in the Vector object from names to
newName.
st
If the 1 argument is -ve, or is greater than or equal to the
current size of the Vector, the method will throw an
ArrayIndexOutOfBoundsException.
String name=Retrieves
th
the 5 vector element in the vector.
names.get(4);
Return type for get() is determined by the type argument
used to create the Vector<> object.
Throws an exception of type
ArrayIndexOutOfBoundsException if the argument is an
illegal index value. The index must be non-negative and
less than the size of the vector.
Removes elements 5
names.removeAll(names.subList(5,15)); to 14, inclusive,
from the Vector<String> object names,
plus any duplicates of those objects that
are in the vector.
Searching a