zoukankan      html  css  js  c++  java
  • 遍历集合List几种方式

    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());   
    •   
    •     }   
    •   
    • }  
  • 相关阅读:
    选择排序
    冒泡排序
    博彦科技面试题笔试题
    智力面试题
    NET中Application,Session,Cookie,ViewState,Cache,Hidden 缓存机制 .
    asp.net/html清理页面缓存的方法
    设置easyui input默认值
    EasyUI分页索引不能输入非数字
    EasyUI Field
    Asp.Net实现无刷新文件上传并显示进度条(非服务器控件实现)(转)
  • 原文地址:https://www.cnblogs.com/huideng/p/4498101.html
Copyright © 2011-2022 走看看