import java.util.*;
//-------------------------------------------------------------------------------
//Using a Vector without generics  
//   if you mix content, then you need to test using instanceof, and cast down
//-------------------------------------------------------------------------------
@SuppressWarnings("unchecked")          //annotation to suppress compile warnings

public class vector1 
{
    public static void main(String[] args) 
    {

        Vector stuff         = new Vector(10);              //not using generics
//      Vector<String> stuff = new Vector<String>(10);      //using generics

        stuff.add(5);                                       //element 0
        stuff.add("Steve");                                 //element 1
        stuff.add(21);                                      //element 2
        stuff.add("Sam");                                   //element 3

        System.out.println(stuff);                          //print the entire list

        Object out = stuff.set(1, "John");                  //replace element1 Steve -> John

        System.out.println("Swapped out: " + out);          //print the swapped out element

        System.out.println(stuff);                          //print the entire list
        System.out.println();

        //Needing to test and down cast to appropriate type before usage

        for (int i=0; i<stuff.size(); i++)
        {
            Object element = stuff.get(i);
            
            if (element instanceof Integer)  
            {
                Integer num = (Integer) element;    //cast down
                num *= 3;
                System.out.println(num);
            }
            if (element instanceof String)  
            {
                String name = (String) element;     //cast down
                name += " Sultan";
                System.out.println(name);
            }           
        }
    }
}