Thursday, 11 December 2014

Java : Collection Framework : Vector (Iterator Remove Elements)


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

VectorExample.java
import java.util.Iterator;
import java.util.Vector;

/*
 * Example of Iterator remove() method.
 */
public class VectorExample
{
    public static void main( String[] args )
    {
        Vector<String> vector = new Vector<String>();
        vector.add("Dave");
        vector.add("Peter");
        vector.add("Phil");

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

        Iterator<String> iterator = vector.iterator();

        while( iterator.hasNext() )
        {
            iterator.next();
            /*
             * Removes from the list the last element that was returned by
             * next()
             */
            iterator.remove();
        }

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


    }
}

Output
vector : [Dave, Peter, Phil]

vector : []


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