Source of VectorDemo.java


  1: 
  2: 
  3: import java.util.*;
  4: 
  5: public class VectorDemo
  6: {
  7:    public static void main(String[] args)
  8:    {
  9:       Vector<String> toDoList = new Vector<String>(10);
 10:       System.out.println(
 11:                     "Enter items for the list, when prompted.");
 12:       boolean done = false;
 13:       String next = null;
 14:       String ans;
 15:       Scanner keyboard = new Scanner(System.in);
 16: 
 17:       while (! done)
 18:       {
 19:           System.out.println("Input an entry:");
 20:           next = keyboard.nextLine( );
 21:           toDoList.addElement(next);
 22:           System.out.print("More items for the list? ");
 23: 
 24:           ans = keyboard.next( );
 25:           keyboard.nextLine( );
 26:           if (!(ans.equalsIgnoreCase("yes")))
 27:                 done = true;
 28:       }
 29: 
 30:       System.out.println("The list contains:");
 31:       int position;
 32:       int vectorSize = toDoList.size( );
 33:       for (position = 0; position < vectorSize; position++)
 34:            System.out.println(toDoList.elementAt(position));
 35:    }
 36: }