|
A good answer might be:
As requested, "Elaine" is inserted at position 2 and all elements previously at position 2 and higher are moved up one to make room.0: Amy 1: Bob 2: Elaine 3: Chris 4: Deb | |
|
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( "Deb" );
System.out.println( names.firstElement() );
System.out.println( names.lastElement() );
}
}
|
The program prints out:
Amy Deb
If there are no elements in the Vector what do you
think happens?