Java Collection Tutorial - Java IdentityHashMap.size()


IdentityHashMap.size() has the following syntax.

public int size()


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, "");
      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.