Apr 13, 2012

Set Interface

Extends Collection and defines a set of elements similar to List.
ü     Does not permit duplication of elements.
ü     Used to create non-duplicate list of object references.
ü     Does not define any additional methods of its own.
public interface Set extends Collection
A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.

Some Important Methods
boolean
add(E o) Adds the specified element to this set if it is not already present.
boolean
addAll(Collection<? extends E> c) Adds all of the elements in the specified collection to this set if they're not already present.
boolean
containsAll(Collection<?> c) Returns true if this set contains all of the elements of the specified collection.
boolean
remove(Object o) Removes the specified element from this set if it is present.
boolean
removeAll(Collection<?> c) Removes from this set all of its elements that are contained in the specified collection.
boolean
retainAll(Collection<?> c) Retains only the elements in this set that are contained in the specified collection.




0 comments :

Post a Comment