Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:29:03+00:00 2026-05-28T16:29:03+00:00

I need a Max-Priority Queue data structure. Looking in Java’s Priority Queue I noticed

  • 0

I need a Max-Priority Queue data structure.

Looking in Java’s Priority Queue I noticed that it is a Min-Priority Queue.

From javadoc:

The head of this queue is the least element with respect to the
specified ordering

I saw that there is the option to provide a custom Comparator and looking at some posts some suggest to use one and do the reverse comparison to achieve the result of a Max Priority Queue.
This seems to me though a “ugly-hack” and perhaps not intuitive.

Is this the only way to have a Max-Priority Queue from the Java’s standard collection?
Is there a more appropriate object I am missing? (E.g. a while back I didn’t realize that Stack was replaced by a Deque…my bad)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:29:04+00:00Added an answer on May 28, 2026 at 4:29 pm

    AFAIK, yes, it’s the best way to have what you want. I really don’t see how it’s an ugly hack. There is no point of providing two different classes if just one is sufficient. If we followed your reasoning, we would have a MinTreeSet and a MaxTreeSet, a MinTreeMap and a MaxTreeMap, etc., all doining exactly the same thing. It’s a classical use of the strategy pattern.

    Just use Collections.reverseOrder() to get a comparator that compares in the reverse order of the natural ordering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a query that will alter a single column from nvarchar(max) to 32.
I need to change the data type of a column from nvarchar(50) to nvarchar(MAX).
I need to get the biggest value from two fields: SELECT MAX(field1), MAX(field2) Now,
I have 10 arbitrary letters and need to check the max length match from
We need to find TOP 10 students (max score 500) from each section of
DECLARE @result varchar(MAX) SELECT NAME FROM Table WHERE ID = @Id I need to
I need to select all numbers N (integers) between @min and @max Is there
I need to set a max year on the DatePickerDialog that I am using
I need a byte generator that would generate values from Byte.MIN_VALUE to Byte.MAX_VALUE. When
I need a function like int f(int min, int max, int x, int chance)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.