79630392

Date: 2025-05-20 12:07:38
Score: 0.5
Natty:
Report link

If you refer jdk 8 it will show threshold like

source code [ github jdk 8 ] : https://github.com/openjdk/jdk8/blob/master/jdk/src/share/classes/java/util/IdentityHashMap.java#L276

but after jdk 8 from jdk 9 to current jdk version if found that the threshold is calculated by

2 * size >= table.length

source code [ github jdk 9 ] :

https://github.com/openjdk/jdk9/blob/master/jdk/src/java.base/share/classes/java/util/IdentityHashMap.java

source code [ github jdk current ] :

https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/IdentityHashMap.java

JDK 8 :  
  private void init(int initCapacity) {
        // assert (initCapacity & -initCapacity) == initCapacity; // power of 2
        // assert initCapacity >= MINIMUM_CAPACITY;
        // assert initCapacity <= MAXIMUM_CAPACITY;

        threshold = (initCapacity * 2)/3;
        table = new Object[2 * initCapacity];
    }
JDK 9 : 
 in put method ;
     private void init(int initCapacity) {
        // assert (initCapacity & -initCapacity) == initCapacity; // power of 2
        // assert initCapacity >= MINIMUM_CAPACITY;
        // assert initCapacity <= MAXIMUM_CAPACITY;

        table = new Object[2 * initCapacity];
    }
 // Use optimized form of 3 * s.
            // Next capacity is len, 2 * current capacity.
            if (s + (s << 1) > len && resize(len))
Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Muthukarthick T