控制台录入将内容添加到集合中,但是在集合遍历的时候变成了死循环,代码在下面,求指点迷津

    ArrayList<String> al = new ArrayList<String>();
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
        String st = sc.next();
        if("quit".equals(st)){
            break;
        }

        al.add(st); 
    } 
    Iterator<String> it = al.iterator();
    System.out.println(al.size());
    String c = null;
    while(it.hasNext()) { //用debug测试这里一直为true ,我猜想是add方法出了问题 牛人求指点

        c = c+it.hasNext();
    }
    System.out.println(c);

//

}

}

 while(it.hasNext()) { //用debug测试这里一直为true ,我猜想是add方法出了问题 牛人求指点
it.moveNext(); //加上
        c = c+it.hasNext();
    }

c = c+it.hasNext();
改成 c=c + it.next();

c = c+it.hasNext();
改成 c=c + it.next();