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

PriorityQueue needs a constructor (Collection, Comparator)

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      The java.util.PriorityQueue class needs a constructor that takes a Collection<? extends E> and a Comparator<? extends E> that creates an instance containing the elements in the Collection and whose elements are ordered according to the specified comparator.

      JUSTIFICATION :
      It is important to have a way to initialize a PriorityQueue with a collection and a comparator in O(n) time

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The new constructor's implementation should set the instance comparator field before calling initFromCollection(), even If the input collection is a PriorityQueue or a SortedSet,
      ACTUAL -
      The developer cannot currently create a PriorityQueue with a collection and a comparator using a constructor.

      CUSTOMER SUBMITTED WORKAROUND :
      The developer must now construct the PriorityQueue with the required comparator, and then use add() or addAll() to add elements to the PriorityQueue, causing the queue to be reorganized after each addition (addAl()l just interactively calls add())

            martin Martin Buchholz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: