GeeCON Prague 2014*
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.
 
Consider Paul's rocket mass heater.
 
subject: Why this program is not printing any values???