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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:46:17+00:00 2026-05-14T06:46:17+00:00

Currently I have to write the following to update an element already contained in

  • 0

Currently I have to write the following to update an element already contained in a Set:

Set mySet= ...
Element e1 = new Element (...);
....
....
Element e2 = new Element (...);
\\e1 and e2 are different instances, but equals.

\\update the element contained into the Set
if (mySet.contains(e2)){
    mySet.remove(e2);
    myset.add(e2);
 }

That doesnt look nice. Is there an alternative ?

  • 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-14T06:46:18+00:00Added an answer on May 14, 2026 at 6:46 am

    A Set is a data structure made to avoid duplicate by mean of using equals() on the object; that also means that two object that are equals() to each other are considered to be perfectly equivalent. Ie, whether you use the version already in the Set or the new one, your code should work the same.

    If you want to update the object with a new value, then this is clearly not the case for you (the two version can not replace each other), and you should then use another data structure (eg, a Map, where you can easily override the value, in this case, the key can even be the object itself).

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

Sidebar

Related Questions

Currently, I have: outByte.writeInt(0x49492a00); outByte.writeInt(0x08000000); But i want to be able to write all
I don't generally write batches , but I currently have a batch that uses
I have a domain (read) and reporting (write) database on the same machine. Currently,
I currently using android NDK to write some native code in C. I have
I currently have this sql statement that I wrote and it works but it's
We currently have the following task ahead, and I'm struggling to find what I
I have a possibly long running program that currently has 4 processes, but could
[Disclaimer]: Currently we are running older SQL Server 2000, but we could update to
I currently have the following code and the data is displayed fine. <logic:iterate name=myList
My Web application is currently using Tapestry 5.2.6. I want to write a new

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.