HashMap.putAll
来源:互联网 发布:在淘宝开店充值赚钱吗 编辑:程序博客网 时间:2024/06/05 20:52
public class HashMapDemo {/** * @param args */public static void main(String[] args) { HashMap hashMap1 = new HashMap(); hashMap1.put("A1", "1"); hashMap1.put("A2", "2"); HashMap hashMap2 = new HashMap(); hashMap1.put("B1", "1"); hashMap1.put("B2", "2"); HashMap hashMap3 = new HashMap(); hashMap3.putAll(hashMap1); hashMap3.putAll(hashMap2); Set entrySet = hashMap3.entrySet(); Iterator iterator = entrySet.iterator(); while(iterator.hasNext()){ Map.Entry next = (Map.Entry)iterator.next(); System.out.println(" key = "+next.getKey()+" value = "+next.getValue()); } }}
输出结果:
key = A1 value = 1
key = B2 value = 2
key = A2 value = 2
key = B1 value = 1
修改:
public class HashMapDemo {/** * @param args */public static void main(String[] args) { HashMap hashMap1 = new HashMap(); hashMap1.put("A1", "1"); hashMap1.put("A2", "2"); HashMap hashMap2 = new HashMap(); hashMap1.put("A1", "1"); //更改 hashMap1.put("A2", "3"); //更改 HashMap hashMap3 = new HashMap(); hashMap3.putAll(hashMap1); hashMap3.putAll(hashMap2); Set entrySet = hashMap3.entrySet(); Iterator iterator = entrySet.iterator(); while(iterator.hasNext()){ Map.Entry next = (Map.Entry)iterator.next(); System.out.println(" key = "+next.getKey()+" value = "+next.getValue()); } }}
输出结果:
key = A1 value = 1
key = A2 value = 3
阅读全文
0 0
- HashMap.putAll
- Map.putAll()用法
- Map.putAll()用法
- Coherence(4)-替代PutAll
- Map.putAll()用法
- Map.putAll()用法
- Map.putAll()用法
- Map.putall()方法
- Map.putAll()的用法
- Map.putAll() 使用方法 简单易懂
- Map的赋值和putAll的区别
- Map集合的putAll()方法的使用。
- Map.putAll(Map<? extends String, ? extends Object> m)方法
- HashMap
- HashMap
- HashMap
- HashMap
- HashMap
- Zend Studio使用教程:使用PHP 7进行开发(一)
- Linux 6上使用UDEV绑定共享存储
- 我是不是应该为这第一篇博客起一个叼炸的名字
- Android零基础入门第17节:TextView属性和方法大全
- AJAX删除
- HashMap.putAll
- Linux下的tar压缩解压缩命令详解
- Linux semaphore 封装实现
- log
- Python程序-1
- I
- linux常用命令
- squid优化及配置参数
- new String("abc")和“abc”的区别