zoukankan      html  css  js  c++  java
  • java迭代map

    java迭代map:

     1 import java.util.HashMap;
     2 import java.util.Iterator;
     3 import java.util.Map;
     4 import java.util.Map.Entry;
     5 
     6 public class TestMap {
     7     /**
     8      * @param args
     9      */
    10     public static void main(String[] args) {
    11         // TODO Auto-generated method stub
    12         Map m = new HashMap();
    13         m.put("sb", "s");
    14         m.put("bs", "b");
    15         Iterator<Entry<String, String>> it = m.entrySet().iterator();
    16          while (it.hasNext()) {
    17              Map.Entry<String, String> entry =  it.next();  
    18              String key = entry.getKey();  
    19              String value = entry.getValue();
    20              System.out.println("key = " + key + "; value = " + value); 
    21          }
    22     }
    23 }
  • 相关阅读:
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
  • 原文地址:https://www.cnblogs.com/lishupeng/p/5601005.html
Copyright © 2011-2022 走看看