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 8827113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:10+00:00 2026-06-14T07:18:10+00:00

For some reason when I add to the priority queue, it doesn’t sort my

  • 0

For some reason when I add to the priority queue, it doesn’t sort my strings entirely alphabetically and I can’t see why.

This is the code which adds to the PriorityBlockingQueue:

String toAdd = String.format("%s/%s", directory, s);
outputData.add(toAdd);

But I get not entirely sorted output (only first few lines but you can see it’s not sorted):

../StartingTree/files/abknl/apfmpohgyh/a.class
../StartingTree/files/abknl/apfmpohgyh/a.java
../StartingTree/files/abknl/aqybc/aeph.java
../StartingTree/files/abknl/apfmpohgyh/bnjuxxdi.class
../StartingTree/files/abknl/bbxudleuf/jlffhq/y/xwjj/dyetqhsch/bpg.class
../StartingTree/files/abknl/bbxudleuf/mxb/fe/ndmg/axapxuco.html
../StartingTree/files/abknl/aqybc/atyuojdu.txt

And this is the real (first part) of sorted output from the expected-output file:

../StartingTree/files/abknl/apfmpohgyh/a.class
../StartingTree/files/abknl/apfmpohgyh/a.java
../StartingTree/files/abknl/apfmpohgyh/bnjuxxdi.class
../StartingTree/files/abknl/apfmpohgyh/bnjuxxdi.java
../StartingTree/files/abknl/apfmpohgyh/bsqsq.class
../StartingTree/files/abknl/apfmpohgyh/bsqsq.java
../StartingTree/files/abknl/apfmpohgyh/ds.class
../StartingTree/files/abknl/apfmpohgyh/ds.java
  • 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-06-14T07:18:11+00:00Added an answer on June 14, 2026 at 7:18 am

    I suspect you are trying to iterate the PriorityBlockingQueue and print the elements.

    Note that a Priority Queue data structure (AKA heap) does not guarantee ordering – it guarantees that the head is minimal, but no order guarantee on any of the following nodes.

    If you want your data maintained sorted – I suggest using something like ConcurrentSkipListSet (Note however it is a set – thus it does not allow duplicate entrees), or maintaining a sorted List.

    If you want to get the sorted elements using a PriorityBlockingQueue – you should iteratively delete the head and output the new head – until the priority queue is exhausted. It will guarantee an ordered output.

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

Sidebar

Related Questions

For some reason I can't get this script to run when I add the
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason Google Page Speed, the add-on to Firebug, doesn't show the Paint
For some reason, I can't add anything to my JList. The JList is visible
For some reason I can't edit XHTML source. Can we add any attributes to
Can't find how to do this for some reason. When clicking the Add_model Entry
For some reason I can not add reference to MS Word file MSWORD.OLB. It
For some reason our developers can only add projects that they've created to Team
For some reason, I can't add new gems (which haven't been donwloaded/used before) to
For some reason .add on the last line doesn't work as expected, all the

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.