Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

251
Views
How do I create a HashSet of unique values without comparison in Java

I have a complex Java Bean with ~20 attributes. In my business logic, I am generating around 10^5 unique instances of this Bean.

The bean has a complex and performance costly equals method.

My API signature is old and I can return the data only in a HashSet data structure.

I require to generate this HashSet from the unique instances without invoking the equals method of the bean to have the flow optimized.

Is it possible?

It is guaranteed, the data to be inserted in HashSet are unique beforehand.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

IdentityHashMap uses == instead of equals() to compare keys when two of them have the same hash code.

You can create a set from it:

Set<E> set = Collections.newSetFromMap(new IdentityHashMap<>());
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!