zoukankan      html  css  js  c++  java
  • 迭代器遍历Map、List、Set

    1、Map的遍历
        Map<Integer,String> maps=new HashMap<Integer,String>();
        maps.put(1,"a");
        maps.put(2,"b");
        maps.put(3,"c");
        
        Iterator<Map.Entry<Integer,String>> itMap=map.entrySet.iterator();
        while(itMap.hasNext){
            Map.Entry<Integer,String> entry=itMap.next();
            System.out.println(entry.getKey()+","+entry.getValue);    
        }    
    
    2、List的遍历
        List<String> lists=new ArrayList<String>();
        lists.add("a");
        lists.add("b");
        lists.add("c");
        
        Iterator<String> itList=lists.iterator();
        while(itList.hasNext()){
            String value=itList.next();
            System.out.println(value);
        }    
    
    3、Set的遍历
        Set<String> set=HashSet<String>();
        set.add("a");
        set.add("b");
        set.add("c");
        
        Interator itSet=set.interator();
        for(itSet.hasNext()){
            String value=itSet.next();
            System.out.println(value);
        }
            
    

      

  • 相关阅读:
    周总结
    周总结
    周总结
    读后感
    周总结
    周总结
    周总结
    第一周总结
    大学生失物招领平台使用体验
    快速乘法+快速幂
  • 原文地址:https://www.cnblogs.com/kongnengjing/p/9434339.html
Copyright © 2011-2022 走看看