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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:58:11+00:00 2026-06-08T14:58:11+00:00

As described in the answer to Double in HashMap , Doubles shouldn’t be used

  • 0

As described in the answer to Double in HashMap, Doubles shouldn’t be used in HashMaps because they are difficult to compare for equality. I believe my case is different, but I thought I’d ask to make sure since I didn’t see anything about this.

I’m going to have a series of double values associated with objects, and I want them to be sorted by the double values. Is TreeMap an appropriate solution? Would there be a better one? The double values are generated a bunch of math, so the likelihood of a duplicate value is extremely low.

EDIT: I should clarify: all I need is to have this list of objects sorted by the doubles they’re associated with. The values of the doubles will be discarded and I’ll never call map.get(key)

  • 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-08T14:58:12+00:00Added an answer on June 8, 2026 at 2:58 pm

    Doubles shouldn’t be used in HashMaps because they are difficult to compare for equality.

    • Will you ever try to get the values based on certain keys?

      • If yes, then the reasoning about “difficult to compare” applies and you should probably avoid such data structure (or always rely on tailMap / headMap / submap and fetch ranges of the map).

      • If no (i.e. you’ll typically just do for (Double key : map.keySet()) ... or iterate over the entrySet) then I would say you’re fine using Double as keys.

    The double values are generated a bunch of math, so the likelihood of a duplicate value is extremely low.

    • Is it a bug if you actually do get a duplicate?

      • If yes then it’s not the right data structure to use. You could for instance use a Multimap from Guava instead.

      • If no, (i.e. it doesn’t matter which of the two values it maps to, because they can only differ by a small epsilon anyway) then you should be fine.

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

Sidebar

Related Questions

I have used code described on below mentioned SO answer Change the image source
I'm implementing shake gestures as described in this answer however if I shake my
In this answer , I described how I resorted to wrappnig a GZipStream around
I'd like to create a few enums such as described in this answer: Lookup
I have made a three-layer application with refrences going as described in this answer
I implemented gesture recognizer in UIMapView just as described in the accepted answer to
I am using CAGradientLayer to create a background layer, as described in this answer
Forcing a particular language for RecognizerIntent is straightforward as described in this answer .
I have question ebout generatong image sitempap as described here: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=178636 If i have
Update: I've added an answer that describes my final solution (hint: the single Expr

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.