zoukankan      html  css  js  c++  java
  • Map的迭代方式有哪几种?

    Map的形式分为四种:

      Map<String,String> map=new HashMap<String,String>();

      map.put("1","没有什么不可以");

      map.put("2","一定可以做到");

      map.put("3","一定行");

      1、通过获取map.keySet的方式

      for(String key:map.keySet()){

        System.out.println("key:"+key+",value:"+map.get(key));

      }

      2、通过迭代器的方式

      Iterator<Map.Entry<String,String>> it=map.entrySet().iterator();

      while(it.hasNext()){

        Map.Entry<String,String> entry=it.next();

        System.out.println("key:"+entry.getKey()+",value:"+entry.getValue());

      }

      3、使用map.entrySet的方式

      for(Map.Entry<String,String> entry:map.entrySet){

        System.out.println("key:"+entry.getKey()+",value:"+entry.getValue());

      }

      4、遍历map.values的方式

      for(String value:map.getValues()){

        System.out.println(value);

      }

  • 相关阅读:
    BGP
    ospf路由认证
    rip路由认证
    php-数组的相关函数及排序算法
    php-多维数组,数组遍历
    php-数组的概念,语法及特点
    php-错误处理
    MySQL性能优化
    JUC多线程03
    JUC多线程01
  • 原文地址:https://www.cnblogs.com/kongnengjing/p/9428976.html
Copyright © 2011-2022 走看看