IdentityHashMap toString() in Java

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

Syntax:

String java.util.AbstractMap.toString()

This method returns a string representation of this map.

Parameters: NA

Returns: a string representation of this map.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMaptoString {

    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.toString());
    }

}

Output:

{Java=1, Hello=2}


No comments:

Post a Comment