java学习中遇到的诡异问题,LinkedList类的输出操作
publicclassLinkedListDemo03{publicstaticvoidmain(String[]args){LinkedList<String>link...
public class LinkedListDemo03 {
public static void main(String[] args) {
LinkedList<String> link = new LinkedList<String>();
link.add("A");
link.add("B");
link.add("C");
System.out.print("以FIFO的方式输出:");
System.out.println(link.size());
for (int i = 0; i < link.size();i++) {
System.out.print(link.poll()+"、");
}
}
}
for循环只会输出:A、B、,这是为何?
将link.size替换3就可以正常输出,实在想不通 展开
public static void main(String[] args) {
LinkedList<String> link = new LinkedList<String>();
link.add("A");
link.add("B");
link.add("C");
System.out.print("以FIFO的方式输出:");
System.out.println(link.size());
for (int i = 0; i < link.size();i++) {
System.out.print(link.poll()+"、");
}
}
}
for循环只会输出:A、B、,这是为何?
将link.size替换3就可以正常输出,实在想不通 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询