IdentityHashMap clone() in Java

clone(): This method is available in java.util.IdentityHashMap class of Java.

Syntax:

Object java.util.IdentityHashMap.clone()

This method returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.

Parameters: NA

Returns: a shallow copy of this map.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMapclone {

    public static void main(String args[]) {

        IdentityHashMap<String, Integer> identityHashMap =
new IdentityHashMap<String, Integer>();

        identityHashMap.put("Java", 1);
        identityHashMap.put("Hello", 2);

        System.out.println(identityHashMap.clone());

    }

}

Output:

{Java=1, Hello=2}


No comments:

Post a Comment