Prev Next

Java / Set and its implementations

How do I update an existing object at HashSet in Java?

Perform remove before adding the element into the HashSet.

 if(!myHashSet.add(myObject)) {
     myHashSet.remove(myObject);
     myHashSet.add(myObject);
 }

More Related questions...

Show more question and Answers...


Comments & Discussions