names.insertElementAt( "Elaine", 2);

A good answer might be:

0: Amy
1: Bob
2: Elaine
3: Chris
4: Deb

As requested, "Elaine" is inserted at position 2 and all elements previously at position 2 and higher are moved up one to make room.

firstElement() and lastElement()

The firstElement() and lastElement() methods are sometimes useful. They do what you imagine:

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

QUESTION 13:

If there are no elements in the Vector what do you think happens?