- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return a shallow copy of IdentityHashMap in Java
Returning a shallow copy means to copy elements of one IdentityHashMap to another. For this, clone() method is used.
The following is an example to return a shallow copy of IdentityHashMap
Example
import java.util.*; public class Demo { public static void main(String[] args) { IdentityHashMap<String, Integer> m = newIdentityHashMap<String, Integer>(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450); System.out.println("IdentityHashMap elements
"+ m); System.out.println("Size = " + m.size()); System.out.println("
Cloned Map = " + m.clone()); 0System.out.println("Size = " + m.size()); } }
Output
IdentityHashMap elements {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10 Cloned Map = {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10
- Related Articles
- Deep Copy and Shallow Copy in Java
- How do you make a shallow copy of a list in Java?
- What is the difference between shallow copy and deep copy in Java?
- Copy - Shallow and deep copy operations in Python
- What is shallow copy? Explain with an example in Java.
- How to create a shallow copy of Hashtable in C#?
- How to create a shallow copy of ArrayList in C#?
- How to create a shallow copy of the BitArray in C#?
- How to create a shallow copy of SortedList Object in C#?
- Python Shallow and Deep Copy operations
- How to shallow copy the objects in JavaScript?
- Create IdentityHashMap in Java
- Clone IdentityHashMap in Java
- IdentityHashMap class in Java
- What is Shallow Copy and how it is different from Deep Copy in C#?

Advertisements