java treemap

TreeMap类putAll()方法 (TreeMap Class putAll() method)

  • putAll() method is available in java.util package.

    putAll()方法在java.util包中可用。

  • putAll() method is used to copy all the key-value pairs from the given map (m) and paste it into this map.

    putAll()方法用于复制给定映射(m)中的所有键值对,并将其粘贴到此映射中。

  • putAll() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    putAll()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • putAll() method may throw an exception at the replacing mappings.

    putAll()方法可能会在替换映射处引发异常。

    • ClassCastException: This exception may throw when the given map (m) elements protect it from being saved in this Map.ClassCastException :当给定的map(m)元素防止将其保存在此Map中时,可能会抛出此异常。
    • NullPointerException: This exception may throw when the given parameter is null exists.NullPointerException :当给定参数为null时,可能引发此异常。

Syntax:

句法:

    public void putAll(Map m);

Parameter(s):

参数:

  • Map m – represents the mappings to be saved in this TreeMap.

    映射m –表示要保存在此TreeMap中的映射。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example
// of void putAll(Map m) method of TreeMap
import java.util.*;
public class PutAllOfTreeMap {public static void main(String[] args) {// Instantiates two TreeMap
TreeMap < Integer, String > tm1 = new TreeMap < Integer, String > ();
TreeMap < Integer, String > tm2 = new TreeMap < Integer, String > ();
// By using put() method is
// to put the key-value pairs in
// treemap tm1
tm1.put(1, "C");
tm1.put(4, "C++");
tm1.put(3, "Java");
tm1.put(2, "Php");
// By using put() method is
// to put the key-value pairs in
// treemap tm2
tm2.put(1, "SQL");
tm2.put(2, "DBMS");
// Display TreeMap tm1
System.out.println("tm1: " + tm1);
// By using putAll() method is to
// put all the elements of tm2 in tm1
tm1.putAll(tm2);
// Display updated TreeMap tm1
System.out.println("tm1.putAll(tm2): " + tm1);
}
}

Output

输出量

tm1: {1=C, 2=Php, 3=Java, 4=C++}
tm1.putAll(tm2): {1=SQL, 2=DBMS, 3=Java, 4=C++}

翻译自: https://www.includehelp.com/java/treemap-putall-method-with-example.aspx

java treemap

java treemap_Java TreeMap putAll()方法与示例相关推荐

  1. java treemap lastkey,java.util.TreeMap.higherKey()方法实例

    全屏 higherKey(K key)方法用于返回最近键严格小于给定键,或null,如果不存在这样的键 声明 以下是java.util.TreeMap.higherKey()方法的声明.public  ...

  2. java散列法的运用实例,Java HashMap compute() 使用方法及示例

    Java HashMap compute() 使用方法及示例 Java HashMap compute()方法计算一个新值,并将其与哈希映射中的指定键相关联. compute()方法的语法为: has ...

  3. math的用法在java中的使用,Java Math cbrt() 使用方法及示例

    Java Math cbrt() 使用方法及示例 Java Math cbrt()方法返回指定数字的立方根. cbrt()方法的语法为: Math.cbrt(double num) 注意:cbrt() ...

  4. java arraylist 方法返回值,Java ArrayList get() 使用方法及示例

    Java ArrayList get() 使用方法及示例 Java ArrayList get()方法返回指定位置存在的元素. get()方法的语法为: arraylist.get(int index ...

  5. java treemap_Java TreeMap size()方法与示例

    java treemap TreeMap类的size()方法 (TreeMap Class size() method) size() method is available in java.util ...

  6. java treemap_Java TreeMap lastKey()方法与示例

    java treemap TreeMap类lastKey()方法 (TreeMap Class lastKey() method) lastKey() method is available in j ...

  7. java treemap_Java TreeMap keySet()方法与示例

    java treemap TreeMap类的keySet()方法 (TreeMap Class keySet() method) keySet() method is available in jav ...

  8. java treemap_Java TreeMap HigherKey()方法与示例

    java treemap TreeMap类HigherKey()方法 (TreeMap Class higherKey() method) higherKey() method is availabl ...

  9. java treemap_Java TreeMap lastEntry()方法与示例

    java treemap TreeMap类的lastEntry()方法 (TreeMap Class lastEntry() method) lastEntry() method is availab ...

最新文章

  1. Azure上的VM代理及可扩展程序
  2. 竟有如此沙雕的代码注释!
  3. 十三种基于直方图的图像全局二值化算法原理、实现、代码及效果。
  4. 笔记-信息系统安全管理-信息系统安全等级保护基本要求
  5. REST面向资源架构 RESTful架构
  6. java常用类总结_java——常用类的总结
  7. uva 138——Street Numbers
  8. WHERE和HAVING子句有什么区别?
  9. RecyclerView.ItemDecoration 间隔线
  10. 【报告分享】2021年网生代线上社交行为洞察报告:95后、00后社交江湖大揭秘.pdf(附下载链接)...
  11. 做了MVC模式一年,可不要把传统模式忘记呀!ashx配合aspx实现AJAX加载JSON数据...
  12. Linux中fcntl函数介绍
  13. 9.5.3 Android Apk 反编译 9.5.4 Android Apk 加密
  14. 雷霄骅《视音频数据处理入门:H.264视频码流解析》(代码注释版)
  15. vsr matlab仿真,电压型PWM整流器(VSR)及控制系统的matlab仿真..docx
  16. 一天十道Java面试题----第四天(线程池复用的原理------>spring事务的实现方式原理以及隔离级别)
  17. 有道云笔记迁移到为知笔记
  18. 【log4j2】下载、安装、使用
  19. LeetCode 09:回文数(Java实现)
  20. 2017移动端UI设计规范模板参考以及设计规范的好处

热门文章

  1. 京东php asp,jd jd demo 关于php的代码里面是 一些京东的接口 包含了 重要 WEB(ASP,PHP,...) 238万源代码下载- www.pudn.com...
  2. python编程序列类型_python序列类型种类详解
  3. 吃鸡服务器8月10日维护,《黑潮之上》2021年8月10日不停服维护公告
  4. React div加载背景图
  5. HTML知识点总结之img、scirpt、link标签
  6. display转块状化
  7. Membership学习(三)Membership Providers介绍[xgluxv]
  8. codeforces 1136E-Nastya Hasn't Written a Legend
  9. 网络基础之 Nmap 命令
  10. sol - 0x60,61,62