• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Set question

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers, could someone please help me in my understanding of Sets. I know how to scroll through a Set but would like to know if its possible to edit a value in a Set. Below is an example of what I would like to do. I would like change the value in the Set from "Hello" to "Goodbye". Is this possible? I fear it may not be as I'm trying to do it.
Thanks
Robbie.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Objects that are in a HashSet should be immutable, because the HashSet relies on the fact that the hash codes of the objects stored in it remain constant. If you put mutable objects in a HashSet and change the value of such an object while it's in the set (so that its hash code changes), the HashSet will get confused. The same is true for the keys of HashMap.

What you can do is remove the old value and insert the new one:
 
robert stannard
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper thats a good answer, I understand it now.

Regards
Robert.
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic