Map map = new HashMap();
map.put("www.aa.com", "www.aaa.com");
map.put("b", "www.bbbb.com");
Iterator<?> it = map.keySet().iterator();
while(it.hasNext()){
String s = (String)map.get(it.next());
System.out.println(s);
}
map.remove("www.aa.com");
while(it.hasNext()){
String s = (String)map.get(it.next());
System.out.println(s);
}
www.bbbb.com作为键
为什么删不掉?

解决方案 »

  1.   

          可以的        Map map = new HashMap();
            map.put("www.aa.com", "www.aaa.com");
            map.put("b", "www.bbbb.com");
            Iterator<?> it = map.keySet().iterator();
            while (it.hasNext())
            {
                String s = (String)map.get(it.next());
                System.out.println("==" + s);
            }
            
            map.remove("www.aa.com");
            it = map.keySet().iterator();        while (it.hasNext())
            {
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
      

  2.   

    www.bbbb.com是作为值,而不是作为键
      

  3.   

    map对象里的删了!但是你Iterator对象用的还是没删以前的!
      

  4.   


    Map map = new HashMap();

            map.put("www.aa.com", "www.aaa.com");
            map.put("b", "www.bbbb.com");
            
            Iterator<?> it = map.keySet().iterator();
           
            while(it.hasNext()){
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
            
            map.remove("www.aa.com");//移除了键值对("www.aa.com", "www.aaa.com")
            
           it = map.keySet().iterator();//重新获得iterator 才能打印
            while(it.hasNext()){
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
      

  5.   


    Map map = new HashMap();
            map.put("www.aa.com", "www.aaa.com");
            map.put("b", "www.bbbb.com");
            Iterator<?> it = map.keySet().iterator();
            while(it.hasNext()){
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
            map.remove("www.aa.com");
            while(it.hasNext()){// 这边已经是false了。
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
    另外你remove的是key,这条记录被删了。map.put("www.aa.com", "www.aaa.com");
    map.put("b", "www.bbbb.com");这个没有被删掉
      

  6.   

    www.aa.com
    作为键值
    删不掉www.aaa.com啊
      

  7.   

    1、4、5楼正解,可以打印一下map.size()就能看到效果了
      

  8.   

    可以的Map map = new HashMap();
            map.put("www.aa.com", "www.aaa.com");
            map.put("b", "www.bbbb.com");
            Iterator<?> it = map.keySet().iterator();
            while(it.hasNext()){
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
            map.remove("www.aa.com");
            while(it.hasNext()){ //下面的都循环都没执行,为false了,实际上map里是移除了的,可以把it再赋值试下
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
      

  9.   

    你把www.bbbb.com作为b对应的值了  而且最后的Iterator最好新建一个
      

  10.   


    Map<String,String> map = new HashMap<String,String>();
            map.put("www.aa.com", "www.aaa.com");
            map.put("b", "www.bbbb.com");
            Iterator<String> it = map.keySet().iterator();
            while(it.hasNext()){
                String s = (String)map.get(it.next());
                System.out.println(s);
            }
            System.out.println("--------删除键www.aa.com----------------");
            map.remove("www.aa.com");
            it = map.keySet().iterator();
            while(it.hasNext()){
             String key=it.next();
                String s = map.get(key);
                System.out.println(s);
                if("www.bbbb.com".equals(s)) map.remove(key);
            }
           System.out.println("--------删除值www.bbbb.com---------------------"); 
            it=map.keySet().iterator();
            while(it.hasNext()){
             System.out.println(map.get(it.next()));
            }