Type Parameters

  • E

Constructors

  • Type Parameters

    • E

    Returns Set<E>

Methods

  • Adds the specified element to this set if it is not already present (optional operation). More formally, adds the specified element e to this set if the set contains no element e2 such that Objects.equals(e, e2). If this set already contains the element, the call leaves the 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 throw an exception, as described in the specification for Collection#add Collection.add. Individual set implementations should clearly document any restrictions on the elements that they may contain.

    Parameters

    • e: E

      element to be added to this set

    Returns boolean

    true if this set did not already contain the specified element

    Throws

    UnsupportedOperationException if the add operation is not supported by this set

    Throws

    ClassCastException if the class of the specified element prevents it from being added to this set

    Throws

    NullPointerException if the specified element is null and this set does not permit null elements

    Throws

    IllegalArgumentException if some property of the specified element prevents it from being added to this set

  • Returns true if this set contains the specified element. More formally, returns true if and only if this set contains an element e such that Objects.equals(o, e).

    Parameters

    • o: any

      element whose presence in this set is to be tested

    Returns boolean

    true if this set contains the specified element

    Throws

    ClassCastException if the type of the specified element is incompatible with this set (optional)

    Throws

    NullPointerException if the specified element is null and this set does not permit null elements (optional)

  • Returns the number of elements in this set (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

    Returns number

    the number of elements in this set (its cardinality)