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

Add a method to Collector that returns a sized supplying mutable result container

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • core-libs
    • None

      When collecting elements from a stream it is not possible for the stream pipeline to inform the collecting supplier of known size when requesting a new mutable result container.

      For example, if the exact size of the stream pipeline is known and results are collected concurrently into a concurrent hash map, then that map can be pre-sized thus ensuring concurrent updates will likely be more efficient as there is less chance of resizes occurring.

      The new method could be:

          default IntFunction<A> sizedSupplier() {
              return i -> supplier().get();
          }

      A -1 can be passed to the sized supplying function if the exact size is not known.

            psandoz Paul Sandoz
            psandoz Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: