Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186958 Need method to create pre-sized HashMap
  3. JDK-8284975

Release Note: New Methods to Create Preallocated HashMaps

    XMLWordPrintable

    Details

      Description

      A new static factory method has been introduced that allows creation of `HashMap` instances that are preallocated to contain an expected number of mappings. After using this method, the new `HashMap` can accommodate the expected number of mappings without being resized. Similarly, there are also new static factory methods for `LinkedHashMap` and `WeakHashMap`. The methods are:

       * HashMap.newHashMap
       * LinkedHashMap.newLinkedHashMap
       * WeakHashMap.newWeakHashMap

      The int-bearing constructors for these classes set the "capacity" (internal table size) which is not the same as the number of mappings that can be accommodated. The capacity is related to the number of mappings by a simple but error-prone calculation. For this reason, programs should use these new static factory methods in preference to the int-bearing constructors.

        Attachments

          Activity

            People

            Assignee:
            smarks Stuart Marks
            Reporter:
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: