❮ Previous Next ❯

Iterator:

Methods:

Iterator interface defines the following three methods:

public booleanhasNext()
public Object next()
public void remove()

let's see a simple example for better understanding:

IteratorDemo.java:

importjava.util.*;
classIteratorDemo
{
public static void main(String args[])
{
ArrayList al=new ArrayList();
for(inti=0;i<=10;i++)
{
al.add(i);
}
System.out.println(al);
Iterator it=al.iterator();
while(it.hasNext())
{
Integer i=(Integer)it.next();
if(i%2==0)
System.out.println(i);
else
it.remove();
}
System.out.println(al);
}
}
Output

[0,1,2,3,4,5,6,7,8,9,10]
0
2
4
6
8
10
[0,2,4,6,8,10]

Limitations :

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved