当前位置: 代码迷 >> J2SE >> 讨论hash键值的有关问题
  详细解决方案

讨论hash键值的有关问题

热度:130   发布时间:2016-04-24 12:34:01.0
讨论hash键值的问题
C# code
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作为键
为什么删不掉?

------解决方案--------------------
可以的

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);
}