Map map = new HashMap();
map.put("m1", "a");
map.put("m2", "b");
map.put("m3", "c");
map.put("m4", "d");
map.put("m5", "e");
map.put("m6", "f");
map.put("m7", "g");
map.put("m8", "h")
rt....

解决方案 »

  1.   

     for(Entry<String, String> entry : map.entrySet()) {
             System.out.println(entry.getKey());
             System.out.println(entry.getValue());
            }
      

  2.   

     map.keySet()
     map.values()
      

  3.   

    for循环里什么意思啊?能给解释下吗?
      

  4.   

    上面这个for循环是JDK1.5之后才有的新格式,大概和下面的for循环等价。
    for(Iterator it = map.entrySet().iterator(); it.hasnext();)
    {
        Entry <String, String> entry = (Entry <String, String>)it.next();
        System.out.println(entry.getKey()); 
        System.out.println(entry.getValue());
    }
      

  5.   

    基本语法
    给个简单的例子
    int []a=new int[10];
    for(int b:a){
    }
    表示对数组a进行遍历,b表示当前遍历的对象
    map.entrySet()返回一个集合.
      

  6.   

    map.values();返回值好象是个set但是我把他转化成set的时候却不能转话,转化成list也出错怎么回事啊 ?
      

  7.   

    public Collection<V> values()
      

  8.   

    方式1for(Iterator it = map.entrySet().iterator(); it.hasnext();)
    {
        Entry entry = (Entry)it.next();
        System.out.println(entry.getKey()); 
        System.out.println(entry.getValue());
    }方式2Iterator it=map.keySet().iterator();
    while(it.hasNext()){
     String key=(String)it.next();
    System.out.println(key);
    }
    Iterator values=map.values().iterator();
    while(values.hasNext()){
     Object value=values.next();
    System.out.println(value);
    }