map中存的是key->value
如果要更新map中存的某对值,直接map.put("","");即可;
执行后,map中与key值匹配的那对值将会被更新
代码:
public class updateMap {
public static void main(String args[]){
Map<String ,String > map = new HashMap<String,String>();
map.put("紫光","华宇");
map.put("亿信","华辰");
Set<Map.Entry<String,String>> set = map.entrySet();
Iterator<Map.Entry<String,String>> _iter = set.iterator();
while(_iter.hasNext()){
Map.Entry<String,String> entry = _iter.next();
System.out.println(entry.getKey()+":"+entry.getValue());
}
}
}
结果:
紫光:华宇
亿信:华辰
代码:
public class updateMap {
public static void main(String args[]){
Map<String ,String > map = new HashMap<String,String>();
map.put("紫光","华宇");
map.put("紫光","华辰");
Set<Map.Entry<String,String>> set = map.entrySet();
Iterator<Map.Entry<String,String>> _iter = set.iterator();
while(_iter.hasNext()){
Map.Entry<String,String> entry = _iter.next();
System.out.println(entry.getKey()+":"+entry.getValue());
}
}
}结果:
紫光:华辰