2013年12月15日星期日

Why is this program calculates the number of elements in the list is unsuccessful ?

Such as title,

import java.util.*;

public class Test
{
public static void main(String [] args)
{
       List<String> list = new LinkedList<String>();
       list.add("111");
       list.add("456");
       list.add("789");
       list.add("123");
                           
       ListIterator<String> x = list.listIterator();
      
       int i = 0;
       while(x.hasNext())
       {
        i++;
       }
       System.out.println(i);                                   
}
}


black window, the mouse has been flashing state, did not show


------ Solution ------- -------------------------------------
plus sentence x in a while loop . next ()
------ For reference only ----------------------------------- ----
really as mentioned above , there are the results. Thank you !

没有评论:

发表评论