IdentityHashMap size() in Java

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

Syntax:

int java.util.IdentityHashMap.size()

This method returns the number of key-value mappings in this identity hash map.

Parameters: NA

Returns: the number of key-value mappings in this map.

Exceptions: NA

Approach

Java

import java.util.IdentityHashMap;

public class IdentityHashMapsize {

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

}

Output:

2


No comments:

Post a Comment