Package java.util
Interface Set

Public Method add

abstract boolean add(Object o)

_INSERT_METHOD_SIGNATURE_HERE_

Description:

Adds the specified element to this set if it is not already present (optional operation).

More formally, adds the specified element, o, to this set if this set contains no element e such that (o==null ? e==null : o.equals(e)). If this set already contains the specified element, the call leaves this set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.

The stipulation above does not imply that sets must accept all elements; sets may refuse to add any particular element, including null, and throwing an exception, as described in the specification for Collection.add. Individual set implementations should clearly document any restrictions on the the elements that they may contain.

Note that basic types cannot be used with this method because they are not of type object. If you want to add e.g. a byte value use the Byte class, see the HashSet example below.

Example

Set MyHashSet = new HashSet(); // HashSet implemnts Set

MyHashSet.add(new Byte((byte)0xAA)); // create a Byte-object