slot 0: Amy slot 1: Bob slot 0: Zoe slot 1: Bob
Vector
A Vector
is a linear list of elements,
just like an array.
As with an array
a counting loop can be used to visit each element in
order.
(Note: an alternate method, using an
Enumeration
will be discussed later.)
The following is an example:
import java.util.* ; class VectorEg { public static void main ( String[] args) { Vector names = new Vector( 10 ); names.addElement( "Amy" ); names.addElement( "Bob" ); names.addElement( "Chris" ); names.addElement( "Dan" ); names.addElement( "Elaine" ); names.addElement( "Fred" ); for ( int j=0; j < names.__________(); j++ ) System.out.println( j + ": " + names.__________(j) ); } }