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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:50:31+00:00 2026-05-19T15:50:31+00:00

More specifically I want an interface to compare objects which can be only compared

  • 0

More specifically I want an interface to compare objects which can be only compared for equality [e.g. complex numbers] but don’t have total order on them.
It should have [Note that it only returns a boolean yes/no]

boolean Equals(T object1, T object2);

and a hashcode function. So that when I distribute them into buckets using objects say to collect “equal” objects, 2 “equal” objects don’t end up in two different buckets.

int getHashCode(T object);

Does Java have one? I searched and couldn’t find it.

I am trying to use this in Hadoop Map Reduce to distribute “equal” objects to same reduce job so that I can operate on all “equal” objects. I only care about whether objects are equal or not and don’t need total order. But if two objects are equal they should have same hash code. Otherwise they will end up in two different reduce jobs.

Please note that I know about equals and hashcode of object. But I want an external comparator which say depends on only part of an object. So object’s notion of equality differs from mine.

  • 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-19T15:50:32+00:00Added an answer on May 19, 2026 at 3:50 pm

    There’s no built-in type that is used for this in Java. It’s a “hole” in the collections design, IMO. There’s the string-specific Collator class which is about as close as it gets, I’m afraid.

    There’s no way of customizing the built-in maps to use a specific kind of equality comparison, worse luck. It’s entirely reasonable to want this functionality, and a real pain that it’s not already present.

    You could create your own such interface of course, and write your own map variants which use it… but having to do so sucks 🙁

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

Sidebar

Related Questions

In .Net (VB more specifically, but that doesn't really matter), is there a way
Can I disable warnings for particular foreach statements and more specifically the invalid argument
my question is analogous to the mailto:email@email.com type of link but is more specifically:
More specifically I want to edit the Settings.apk and add more options. I'm unsure
More specifically, I'm trying to check if given string (a sentence) is in Turkish.
I was of the idea that flash (more specifically Adobe's flash player browser plugin)
Is there stable linear algebra (more specifically, vectors, matrices, multidimensional arrays and basic operations
How do I tell if gcc (more specifically, g++) is optimizing tail recursion in
What is the MIME type of javascript? More specifically, what is the right thing
I have some questions about logging, more specifically about setting it up and making

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.