Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8284780

Need methods to create pre-sized HashSet and LinkedHashSet

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 19
    • None
    • core-libs
    • None

    Description

      Pre-allocation of HashSet and LinkedHashSet has similar problems as HashMap: constructors for HashSet and LinkedHashSet take a capacity argument instead of the expected number of elements. This difference is a source of errors. Even if code attempts to compute the desired capacity from the expected number of elements, the computation is surprisingly difficult to get right. (See JDK-8186958, which covers this issue for HashMap et. al.)

      Methods similar to those added by JDK-8186958 should be added to cover creation of HashSet and LinkedHashSet.

      Use sites include the following files:

      src/java.base/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java

      src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java

      Attachments

        Issue Links

          Activity

            People

              smarks Stuart Marks
              smarks Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: