wushuo-1992
 1 public class testList {
 2 
 3 public static void main(String[] args){
 4     List<String> list = new ArrayList<String>();
 5     list.add("a");
 6     list.add("b");
 7     list.add("c");
 8     list.add("d");
 9 
10 //    增强for循环遍历
11     for(String value:list){
12         System.out.println("增强for循环遍历的值"+value);
13     }
14     
15 //    Iterator 遍历
16 //    方法一
17     for(Iterator ite=list.iterator();ite.hasNext();){
18         System.out.println("iterator遍历结果为:"+ite.next());
19     }
20 //    方法二
21     Iterator<String> ite1 = list.iterator();
22     while (ite1.hasNext()) {
23         System.out.println("iterator+while结果为"+ite1.next());        
24     }
25 
26 //    for循环遍历
27     for(int i=0;i<list.size();i++){
28         System.out.println("for循环遍历"+list.get(i));
29     }
30     

 



执行结果为:
增强for循环遍历的值a
增强for循环遍历的值b
增强for循环遍历的值c
增强for循环遍历的值d

iterator遍历结果为:a
iterator遍历结果为:b
iterator遍历结果为:c
iterator遍历结果为:d

iterator+while结果为a
iterator+while结果为b
iterator+while结果为c
iterator+while结果为d

for循环遍历a
for循环遍历b
for循环遍历c
for循环遍历d


 

分类:

技术点:

相关文章:

  • 2021-11-04
  • 2021-10-19
  • 2021-11-04
  • 2021-10-19
  • 2021-11-04
  • 2021-11-04
  • 2021-12-31
猜你喜欢
  • 2021-11-04
  • 2021-08-15
  • 2021-11-04
  • 2021-11-17
  • 2021-11-04
  • 2021-10-03
相关资源
相似解决方案