zoukankan      html  css  js  c++  java
  • map集合的putAll()方法

    今天在公司的项目中又看到大量的时候map结构的putAll()方法,特意记录一下

    废话不多说,上代码:

    package com.zyq;
    
    import java.util.HashMap;
    
    public class A {
        public static void main(String[] args) {
            //两个map具有不同的key
            HashMap map1=new HashMap();
            map1.put("1", "A");
            HashMap map2 = new HashMap();
            map2.put("2", "B");
            map2.put("3", "C");
            map1.putAll(map2);
            System.out.println(map1);
    
    
            //两个map具有重复的key
            HashMap map3=new HashMap();
            map3.put("1", "A");
            HashMap map4 = new HashMap();
            map4.put("1", "B");
            map4.put("3", "C");
            map3.putAll(map4);
            System.out.println(map3);
        }
    }

    运行结果:

    {1=A, 2=B, 3=C}
    {1=B, 3=C}

  • 相关阅读:
    HttpClient
    充值保存
    button 样式
    创建窗口
    第十一次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
    第六次作业
  • 原文地址:https://www.cnblogs.com/dongyaotou/p/14691944.html
Copyright © 2011-2022 走看看