wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why this program is not printing any values??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why this program is not printing any values???" Watch "Why this program is not printing any values???" New topic
Author

Why this program is not printing any values???

Ivaturi Srinivas
Ranch Hand

Joined: Jun 03, 2003
Posts: 42
import java.util.*;
public class SetExample {
public static void main(String args[]) {

List lst = new ArrayList();
lst.add("akp");
lst.add("me");
lst.add("ramki");
ListIterator iterator = lst.listIterator(lst.size());
while(iterator.hasNext())
{

System.out.println((String)iterator.next());
}
}
}
fei peng
Ranch Hand

Joined: Sep 15, 2003
Posts: 40
Hi,Srinivas
I think the index of list is 0 based,the index list.size() means the bottom of list,so it contain no elements.
Ivaturi Srinivas
Ranch Hand

Joined: Jun 03, 2003
Posts: 42
Yes
You are right Thanks, I should not use lst.size() as parameter to print the Arraylist values. I removed that and able to print.
 
jQuery in Action, 2nd edition
 
subject: Why this program is not printing any values???
 
Similar Threads
Reverse the order of elements in a ArrayList
Divide a vector
Why I get the List content when I print the List object?
Should we consider this also as platform dependent?
generic question