
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
670
|
Chapter 11: Data Structures and Algorithms
Discussion
Sets are containers that hold a group of homogeneous object types. Various mathe-
matical operations can be performed on sets, including the following:
Union
(
A ∪ B)
Combines all elements of set
A and set B into a resulting Set<T> object. If an
object exists in both sets, the resulting unioned
Set<T> object contains only one
of those elements, not both.
Intersection
(
A ∩ B)
Combines all elements of set
A and set B that are common to both A and B into a
resulting
Set<T> object. If an object exists in one set and not the other, the ele-
ment is not added to the intersectioned
Set<T> object.
Difference
(
A-B)
Combines all elements of set
A, except for the elements that are also members of
set
B, into a resulting Set<T> object. If an object exists in both sets A and B,itis
not added to the final differenced
Set<T> object. The difference is equivalent to
taking the union of both sets and the intersection of both sets and then remov-
ing all elements in the unioned set that exist in the intersectioned set.
Subset
(
A ⊂ B)
Returns
true if all elements of set A are contained in a second set B; otherwise, it
returns
false. Set B may contain elements not found in A.
Superset
(
A ⊃ B)
Returns
true if all elements of set A are contained in a second set B; otherwise, ...