首页 > 其他 > 详细

遍历集合List几种方式

时间:2015-05-12 18:32:42      阅读:156      评论:0      收藏:0      [点我收藏+]

import java.util.ArrayList;   

  • import java.util.Iterator;   
  • import java.util.List;   
  •   
  • /**  
  •  *遍历集合List  
  •  * @author 够潮  
  •  *  
  •  */  
  • public class Demo35 {   
  •   
  •     /**  
  •      * @param args  
  •      */  
  •     public static void main(String[] args) {   
  •        
  •         List list = new ArrayList();   
  •         list.add("gouchao");   
  •         list.add("gouli");   
  •         //下标   
  •         for(int i = 0 ; i< list.size();i++){   
  •                
  •             System.out.println(list.get(i));   
  •         }   
  •         //for- each   
  •         for(Object o:list){   
  •             System.out.println(o);   
  •         }   
  •         //迭代器   
  •         Iterator it = list.iterator();   
  •         while(it.hasNext()){   
  •             System.out.println(it.next());   
  •         }   
  •         //Object数组    
  •         Object o[];   
  •         o = list.toArray();   
  •         for(int i =  0 ; i <o.length;i++){   
  •             System.out.println(o[i]);   
  •         }   
  •         //toString   
  •         System.out.println(list.toString());   
  •   
  •     }   
  •   
  • }  

 

遍历集合List几种方式

原文:http://www.cnblogs.com/huideng/p/4498101.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!