读书人

HashMap 中 public void putAll(Maplt;

发布时间: 2012-12-26 14:39:29 作者: rapoo

HashMap 中 public void putAll(Map<? extends K,? extends V> m) 的用法

//从指定映射中将所有映射关系复制到此映射中


public class TestPutAll {
?public static void main(String[] args){
??HashMap map1=new HashMap();
??map1.put("a", 1);
??map1.put("b", 2);
??map1.put("c", 3);
??map1.put("d", 4);
??
??HashMap map= new HashMap();
??map.put("e", 5);
??map.put("f", 6);
??map.put("j", 7);
??????? map.putAll(map1);
???????
??????? Iterator ite=map.entrySet().iterator();
??????? while(ite.hasNext()){
??????? ?Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>)ite.next();
??????? ?System.out.print(entry.getKey()+"/");
??????????? System.out.println(entry.getValue());
??????? }
?}

}

读书人网 >编程

热点推荐