Save
Java part 2
Sets
Save
Share
Learn
Content
Leaderboard
Learn
Created by
Ruby
Visit profile
Cards (7)
dynamic
data structure that stores
non-duplicate elements
Sets
Hash Set
elements are
unordered
import java.util.HashSet;
Linked Hash Set
elements are
ordered based on the sequence elements were added
import java.util.LinkedHashSet;
Tree Set
elements are sorted based on their ASCII values
import java.util.TreeSet;
Add
elements
add
an elemnt to the set if it is not already present
returns true if the element was added to the set, otherwise returns false
objectName.add();
remove
elements
removes an element if it's present
returns true
if an element was removed from the
set
, otherwise returns false
objectName.remove();
cardinality
number
of elements contained in the set