Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why this program is not printing any values???

 
Ivaturi Srinivas
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic