![]() |
In Java, a TreeMap is a Map implementation that stores key-value pairs in a red-black tree structure. It allows insertions and deletions of key-value pairs due to its tree implementation. These operations take O(log n) time on average. In this article, we will be learning how to copy key-value pairs from one TreeMap to another in Java. Syntax:newTreeMap.putAll(originalTreeMap);
This will copy all the key-value pairs from originalTreeMap to newTreeMap. Program to Copy Key-Value Pairs from One TreeMap to Another in JavaTo copy key-value pairs from one TreeMap to another, we can use putAll() method. Below is the code implementation for this: Java
Output
Course TreeMap: {AWS=25000, Core Java=10000, Spring Boot=20000} New Course TreeMap: {AWS=25000, Core Java=10000, Spring Boot=20000} Explanation of the above Program:
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |