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

  • Home
  • SEARCH
  • 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 6762593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:22:27+00:00 2026-05-26T14:22:27+00:00

I am trying to get from localNodes the Node who has the minimum distance

  • 0

I am trying to get from localNodes the Node who has the minimum distance from the hashmap distance. the problem when am changing any value in the distance hashmap the queue is not reordered i think the problem is because i am implemting the comparator interface like that which will be as an inner class and enforce me to declare the hashmap as final.
is there any different method.

    final HashMap<Node, Double> distance = new HashMap<>();
    PriorityQueue<Node> localNodes = new PriorityQueue<>(10,
            new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    return distance.get((Node)o2).compareTo(distance.get((Node)o2) );
                }
            });
  • 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-26T14:22:28+00:00Added an answer on May 26, 2026 at 2:22 pm

    You can’t change the relative ordering of elements (in this case, by changing the distance values they map to) that are already in a sorted collection such as a PriorityQueue or SortedSet and expect their position in that collection to change as a result. For one thing, the data structures just aren’t built for that. For another, in your example the PriorityQueue will not be notified of any changes you make to the HashMap so it wouldn’t be able to respond to that even if it were designed to do so.

    I don’t know how you’re using this queue, but one possible solution would be to just store the nodes in your HashMap and create a new PriorityQueue whenever you change the HashMap. The newly created queue will have the correct ordering.

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

Sidebar

Related Questions

Im trying to get values from a ListBox that has multiselection and dynamic ListItems
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I'm trying to get from an Android Uri to a byte array. I have
I'm trying to get from Line #1 to Line #2 in the below code:
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I'm trying to get content from an RSS2 feed from one of my sites
i am trying to get date from my implementation of jquery date picker, add
I'm trying to get the FROM email address in Mule ESB. I'm getting the
I'm working with PyQt and trying to get video from a webcam to play
What is the best way of handling trying to get data from a DataReader

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.