Java Collection Tutorial - Java IdentityHashMap.size()








Syntax

IdentityHashMap.size() has the following syntax.

public int size()

Example

In the following code shows how to use IdentityHashMap.size() method.

/*from w w  w.ja v  a  2 s  .c om*/

import java.util.IdentityHashMap;

public class Main {
   public static void main(String args[]) {

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

      ihmap.put(1, "from");
      ihmap.put(2, "java2s.com");
      ihmap.put(3, "tutorial");
      
      System.out.println("Value of ihmap before: " + ihmap);
      System.out.println("Size of the map: " + ihmap.size());
   }    
}

The code above generates the following result.