Wednesday 10 December 2014

Java : Collection Framework : Vector (Remove element based on Index)

VectorExample.java
import java.util.Vector;

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

        vector.add(100);
        vector.add(40);
        vector.add(30);
        vector.add(50);

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

        /*
         * Removes the element at the specified position in this Vector. Shifts
         * any subsequent elements to the left (subtracts one from their
         * indices). Returns the element that was removed from the Vector.
         */

        Integer removedElement = vector.remove(1);

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

    }
}

Output
vector  : [100, 40, 30, 50]

removedElement  : 40
vector  : [100, 30, 50]

To Download VectorDemoRemoveIndex Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/VectorDemoRemoveIndex.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