Wednesday 10 December 2014

Java : Collection Framework : Vector (Remove Element)


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

VectorExample.java
import java.util.Vector;

/*
 *  Example of removeElement(Object obj) 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);
        vector.add(400);

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

        /*
         * Removes the first (lowest-indexed) occurrence of the argument from
         * this vector. If the object is found in this vector, each component in
         * the vector with an index greater or equal to the object's index is
         * shifted downward to have an index one smaller than the value it had
         * previously. 
         * 
         * This method is identical in functionality to the
         * remove(Object) method (which is part of the List interface).
         */

        Integer element = 300;
        boolean isRemoved = vector.removeElement(element);

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

    }
}

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

isRemoved  : true
vector  : [100, 200, 400]

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

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

    1. We are added much functionality in this Remove object from photo and Remove BG from photo app like remover, clone stamp, background eraser, quick remover, transparent background and cloth remover.

      ReplyDelete