sample code to demonstrate ListIterator
package collection;
import java.util.LinkedList;
import java.util.ListIterator;
public class ListIteratorDemo {
public static void main(String arg[])
{
LinkedList l=new LinkedList();
l.add("laxman");
l.add("chandu");
l.add("ravi");
l.add("raju");
System.out.println(l);
ListIterator lt=l.listIterator();
while(lt.hasNext())
{
String s=(String)lt.next();
if(s.equals("laxman"))
{
lt.remove(); // or lt.set("scjp");
}
else{
System.out.println(s);
}
}
}
}
output:
[laxman, chandu, ravi, raju]
chandu
ravi
raju
0 comments:
Post a Comment