Friday 17 October 2014

Java : Collection Framework : ArrayList (ListIterator Index)



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

ArrayListExample.java
import java.util.ArrayList;
import java.util.ListIterator;

/*
 * Example of listIterator(int index) method
 */
public class ArrayListExample
{

    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");

        ListIterator<String> listIterator = arrayList.listIterator(2);

        /*
         * Using ListIterator move the cursor in forward direction and get each
         * element.
         */

        System.out.println("Forward Direction -----" + "\n");

        while (listIterator.hasNext())
        {
            int nextIndex = listIterator.nextIndex();
            String name = listIterator.next();
            System.out.println(nextIndex + " : " + name);

        }

    }

}

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

Forward Direction -----

2 : Peter
3 : Julia
4 : Akram

To Download ArrayListDemoListIteratorIndex Project Click the below link

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