String str2 = String.valueOf(it2.next());有问题,跳过了几行

解决方案 »

  1.   

    the size of al2 is three, viz the size of it2 is three ,so the result is three lows. 
      

  2.   

    the key is it2.next(). u should do as this:import java.util.*;class a 
    {
    public static void main(String[] args) 
    {
    ArrayList al1 = new ArrayList();
    ArrayList al2 = new ArrayList();
    int i,j;
    for (i=1;i<4 ;i++ ){
    al1.add("al1"+i);
    al2.add("al2"+i);
    } Iterator it1 = al1.iterator();
    //Iterator it2 = al2.iterator(); while (it1.hasNext())
    {
    String str1 = String.valueOf(it1.next());
    //while (it2.hasNext())
    for(Iterator it2=al2.iterator();it2.hasNext();)
    {
    String str2 = String.valueOf(it2.next());
    System.out.println(str1+" "+str2);
    }

    }

    try again.