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.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作为键
为什么删不掉?
解决方案 »
- java中往mysql中存图片
- 再发问题 BMP图片显示问题
- 也发一份的我邮箱,[email protected] ,谢谢了
- 请问如何显示图片,并在上面画线?
- 2个简单问题
- 关于java中方法的大写和小写问题(问题很简单,这分很容易得)
- 求助!关于JButton批量增加的问题,急!!!
- 散分了,喜欢的朋友来领分吧,hh
- 在Red hat linux7.2下,用阳春白雪汉化了Linux,但jbuilder6中不能显示汉字
- 请问在java里面如何调用系统当前的时间?
- JfreeChart画折线图时我想把X轴范围固定成“1时~24时”这个范围怎么写
- java里有类似delphi中的char()方法吗?半夜了,谢谢!
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);
}
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);
}
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");这个没有被删掉
作为键值
删不掉www.aaa.com啊
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);
}
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()));
}