This Java Example shows how to get clone of the HashMap object in java.
Get Clone of Java HashMap Example
This Java Example shows how to get clone of the HashMap object in java. To
get clone of the HashMap object we use Object clone() method. This method
returns a shallow copy of this HashMap instance.the keys and values themselves are not cloned.
Example: CloneOfHashMap.java
package devmanuals.com; import java.util.*; public class CloneOfHashMap { public static void main(String args[]) { HashMap hm = new HashMap(); hm.put(1, "Gyan"); hm.put(2, "Ankit"); hm.put(3, "Arun"); hm.put(4, "Anand"); hm.put(5, "Ram"); System.out.println("The Entries of map are : " + hm); System.out.println("The Entries of clone map are :" + hm.clone()); } }
Output:
The Entries of map are : {1=Gyan, 2=Ankit, 3=Arun, 4=Anand, 5=Ram}
The Entries of clone map are : |
[ 0 ] Comments