Wednesday, 10 December 2014

Java : Collection Framework : Vector (InsertElementAt)

VectorExample.java
import java.util.Vector;

/*
 *  Example of insertElementAt(E obj, int index) method. 
 */
public class VectorExample
{
    public static void main( String[] args )
    {
        Vector<Integer> vector = new Vector<>();

        vector.add(10);
        vector.add(20);
        vector.add(30);
        vector.add(40);
        vector.add(50);

        System.out.println("vector  : " + vector + "\n");

        /*
         * Inserts the specified object as a component in this vector at the
         * specified index. Each component in this vector with an index greater
         * or equal to the specified index is shifted upward to have an index
         * one greater than the value it had previously.
         */

        vector.insertElementAt(4000, 1);

        System.out.println("vector  : " + vector + "\n");

    }
}

Output
vector  : [10, 20, 30, 40, 50]

vector  : [10, 4000, 20, 30, 40, 50]




To Download VectorDemoInsertElementAt Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoInsertElementAt.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge