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());
}
}
}
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());
}
}
}
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