Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda