Friday, 10 October 2014

Java : Collection Framework : ArrayList (Remove elements using Iterator)
























Click here to watch in Youtube : https://www.youtube.com/watch?v=RdMPFhyLPbs

ArrayListIteratorRemoveExample.java
import java.util.ArrayList;
import java.util.Iterator;

/*
 * Example of Iterator remove() method
 */
public class ArrayListIteratorRemoveExample
{

    public static void main( String[] args )
    {
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Ram");
        arrayList.add("Dave");
        arrayList.add("Peter");
        arrayList.add("Julia");
        arrayList.add("Akram");

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

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

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

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

    }

}

Output
arrayList : [Ram, Dave, Peter, Julia, Akram]

arrayList : []


To Download ArrayListDemoItrRemove Project Click the below link

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