牛骨文教育服务平台(让学习变的简单)
博文笔记

Map集合的putAll()方法的使用。

创建时间:2016-06-17 投稿人: 浏览次数:4463

Map集合的putAll()方法的使用。

用途:将指定的Map集合添加到现有的Map集合当中:

测试代码如下:

package test;


import java.util.HashMap;
import java.util.Map;


/**
 * @author : suyuyuan
 * @date :2016年5月11日 上午10:01:56
 * @version 1.0
 */
public class test {


public static void main(String[] args) {


Map<Object, Object> params = new HashMap<Object, Object>();
params.put(1, 11);
params.put(2, 22);
for (Map.Entry<Object, Object> entry : params.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
System.out.println("=========");
}


Map<Object, Object> paramsAppend = new HashMap<Object, Object>();
paramsAppend.put(3, 33);
paramsAppend.put(5, 55);
for (Map.Entry<Object, Object> entryAppend : paramsAppend.entrySet()) {
System.out.println(entryAppend.getKey());
System.out.println(entryAppend.getValue());
System.out.println("=========");


}


params.putAll(paramsAppend);      //此处调用putAll()方法。


for (Map.Entry<Object, Object> append : params.entrySet()) {
System.out.println("append");
System.out.println(append.getKey());
System.out.println(append.getValue());
System.out.println("end");


}


}
}

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。