Monday, 9 March 2015

Looping ArrayList

Here are the three ways to loop through the ArrayList.

import java.util.*;
import java.lang.*;

class Rextester

    public static void main(String args[])
    {
        List<Integer> list = new ArrayList<Integer>();
        list.add(10);
        list.add(20);
       
        for(int i=0;i<list.size();i++)
        {
            System.out.println(list.get(i));
        }
       

        for(Integer num : list)
        {
            System.out.println(num);
        }

       
        Iterator<Integer> it = list.iterator();
        while(it.hasNext())
        {
            System.out.println(it.next());
        }

    }
}

1 comment:

  1. Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best. Applications built using Sencha

    ReplyDelete

AWS Data Pipeline Services

https://www.youtube.com/watch?v=tykcCf-Zz1M