zoukankan      html  css  js  c++  java
  • Map遍历

    今天去中科软面试,笔试题中有一道是遍历Map集合。本人用过for,IteratorI遍历过List集合对于如何遍历Map集合确实头大。回来后在网上看大牛用IteratorI遍历Map集合一时感慨颇多,下面是自己写的Map遍历集合。

    同时也可以用for来遍历集合:提供伪代码有兴趣的同学可以实现一下。

    for(int i=1;i<maps.size;i++){

    System.out.println(maps.get("str"+i));//"str"+i 是map集合中的key

    }

    *********************************

    package TestFor0501;

    import java.util.Collection;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;

    public class TraverseForMap {

    public static void main(String[] args) {
    Map<String,String> maps = mapMathod();
    Collection<String> c = maps.values();
    Iterator it=c.iterator();

    while(it.hasNext()){
    System.out.println(it.next());
    }

    }

    public static Map<String,String> mapMathod(){
    Map<String,String> maps=new HashMap<String,String>();

    for(int i=1;i<100;i++){
    maps.put("str"+i, i+"");
    }

    return maps;
    }
    }

  • 相关阅读:
    爬虫之Selenium库
    爬虫之pyquery库
    爬虫之BeautifulSoup库
    爬虫之Requests库
    爬虫之Re库
    在Flask中使用Celery
    Celery-分布式任务队列
    MongoDB
    Redis Cluster
    如何使用mongo shell
  • 原文地址:https://www.cnblogs.com/DeepBlues/p/3055118.html
Copyright © 2011-2022 走看看