As we know two Set
instances are equal iff they contain the same elements, BUT is it possible to have the same element in two different sets (Set
interface can not contain duplicate element)?
views:
177answers:
3
+2
A:
Distinct sets have no affect on one another. Set A can contain '123456', and Set B can also contain '123456' - the prohibition on duplicates is for a single instance, not across instances.
Equality for two sets implies that their contents are identical.
Visage
2009-06-29 07:59:01
There are all sorts of problems that come up with defining "equality". I believe the java.uti.set subclasses all use the objects .equals method to check if one object is equal to another. Another way to define this is to use the == operator in Java, which is what I believe the .equals method defaults to unless it is overwritten. There are quite a few subtleties with sets to consider without even going into Bertrand Russels set theory paradox.
ldog
2009-06-29 20:08:22
+2
A:
You are not comparing the elements inside a Set with each other to detect if they are equal, you are comparing the Elements of Set1 with the elements of Set2.
Markus Lausberg
2009-06-29 08:01:48