Vector Class Example


import java.util.Vector;

public class VectorTestClass {

    public static void main(String[] args) {

        Vector v = new Vector();

        v.add(new String("Test"));
        v.add(new Integer("123"));
        v.add(new Boolean("true"));
        v.add(6789);
        v.add(new Float(67.78));

        System.out.println("Element at index position 1:  "+v.elementAt(1));

        // to remove element stored at index 3 ie. 6789
            v.remove(3);

        for (int i=0; i<v.size(); i++ )
        {
            System.out.println(v.get(i));
        }

        //or
        /* for (Object a : v.toArray())
        {
            System.out.println(a);
        }
        */

    }

}

Comments

Popular posts from this blog

Custom Exception example for BankAccount

HashMap HashSet example

Annotation