java.util.IdentityHashMap.clone() Method


Advertisements


Description

The clone() method is used to return a shallow copy of this identity hash map.

Declaration

Following is the declaration for java.util.IdentityHashMap.clone() method.

public Object clone()

Parameters

  • NA

Return Value

The method call returns a shallow copy of this map.

Exception

  • NA

Example

The following example shows the usage of java.util.IdentityHashMap.clone()

package com.tutorialspoint;

import java.util.*;

public class IdentityHashMapDemo {
   public static void main(String args[]) {
   // create two identity hash maps 
   IdentityHashMap ihmap = new IdentityHashMap();
   IdentityHashMap ihmapclone = new IdentityHashMap();
 
   // populate the 1st map
   ihmap.put(1, "java");
   ihmap.put(2, "util");
   ihmap.put(3, "package");
      
   System.out.println("Initial Map content: " + ihmap);
      
   // clone the map
   ihmapclone=(IdentityHashMap)ihmap.clone();

   System.out.println("Cloned map content: " + ihmapclone);
   }    
}

Let us compile and run the above program, this will produce the following result.

Initial Map content: {1=java, 3=package, 2=util}
Cloned map content: {1=java, 3=package, 2=util}

java_util_identityhashmap.htm

Advertisements