Monday, 8 December 2014

Java : Collection Framework : Vector (Add Object in the Specific Index Position)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=7dRNGnio5FY&list=UUhwKlOVR041tngjerWxVccw

VectorExample.java
import java.util.Vector;

/*
 *  Example of add(int index, E element) method 
 */
public class VectorExample
{

    public static void main(String[] args)
    {
        Vector<Integer> vector = new Vector<Integer>();

        vector.add(100);
        vector.add(200);
        vector.add(300);

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

        /*
         * Inserts the specified element at the specified position in this
         * Vector. Shifts the element currently at that position (if any) and
         * any subsequent elements to the right (adds one to their indices).
         */
        vector.add(1, 400);

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

    }
}
Output
vector  : [100, 200, 300]

vector  : [100, 400, 200, 300]




To Download VectorDemoAddIndex Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/VectorDemoAddIndex.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