Condividi tramite


ISet Interface

Definition

A collection that contains no duplicate elements.

[Android.Runtime.Register("java/util/Set", "", "Java.Util.ISetInvoker")]
[Java.Interop.JavaTypeParameters(new System.String[] { "E" })]
public interface ISet : IDisposable, Java.Interop.IJavaPeerable, Java.Util.ICollection
[<Android.Runtime.Register("java/util/Set", "", "Java.Util.ISetInvoker")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "E" })>]
type ISet = interface
    interface ICollection
    interface IIterable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

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.

The Set interface places additional stipulations, beyond those inherited from the Collection interface, on the contracts of all constructors and on the contracts of the add, equals and hashCode methods. Declarations for other inherited methods are also included here for convenience. (The specifications accompanying these declarations have been tailored to the Set interface, but they do not contain any additional stipulations.)

The additional stipulation on constructors is, not surprisingly, that all constructors must create a set that contains no duplicate elements (as defined above).

Note: Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set. A special case of this prohibition is that it is not permissible for a set to contain itself as an element.

Some set implementations have restrictions on the elements that they may contain. For example, some implementations prohibit null elements, and some have restrictions on the types of their elements. Attempting to add an ineligible element throws an unchecked exception, typically NullPointerException or ClassCastException. Attempting to query the presence of an ineligible element may throw an exception, or it may simply return false; some implementations will exhibit the former behavior and some will exhibit the latter. More generally, attempting an operation on an ineligible element whose completion would not result in the insertion of an ineligible element into the set may throw an exception or it may succeed, at the option of the implementation. Such exceptions are marked as "optional" in the specification for this interface.

<h2>"unmodifiable">Unmodifiable Sets</h2>

The Set#of(Object...) Set.of and Set#copyOf Set.copyOf static factory methods provide a convenient way to create unmodifiable sets. The Set instances created by these methods have the following characteristics:

<ul> <li>They are <i>unmodifiable</i>. Elements cannot be added or removed. Calling any mutator method on the Set will always cause UnsupportedOperationException to be thrown. However, if the contained elements are themselves mutable, this may cause the Set to behave inconsistently or its contents to appear to change. <li>They disallow null elements. Attempts to create them with null elements result in NullPointerException. <li>They are serializable if all elements are serializable. <li>They reject duplicate elements at creation time. Duplicate elements passed to a static factory method result in IllegalArgumentException. <li>The iteration order of set elements is unspecified and is subject to change. <li>They are value-based. Programmers should treat instances that are #equals(Object) equal as interchangeable and should not use them for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail. Callers should make no assumptions about the identity of the returned instances. Factories are free to create new instances or reuse existing ones. <li>They are serialized as specified on the Serialized Form page. </ul>

This interface is a member of the Java Collections Framework.

Added in 1.2.

Java documentation for java.util.Set.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
IsEmpty

Returns true if this set has no elements.

JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Add(Object)

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

AddAll(ICollection)

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Clear()

Removes all of the elements from this set (optional operation).

Contains(Object)

Returns true if this set contains the specified element.

ContainsAll(ICollection)

Returns true if this set contains all of the elements of the specified collection.

CopyOf(ICollection)

Returns an unmodifiable Set containing the elements of the given Collection.

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Equals(Object)

Compares the specified object with this set for equality.

Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
ForEach(IConsumer)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

(Inherited from IIterable)
GetHashCode()

Returns the hash code value for this set.

Iterator()

Returns an iterator over the elements in this set.

Of()

Returns an unmodifiable set containing zero elements.

Of(Object)

Returns an unmodifiable set containing one element.

Of(Object, Object)

Returns an unmodifiable set containing two elements.

Of(Object, Object, Object)

Returns an unmodifiable set containing three elements.

Of(Object, Object, Object, Object)

Returns an unmodifiable set containing four elements.

Of(Object, Object, Object, Object, Object)

Returns an unmodifiable set containing five elements.

Of(Object, Object, Object, Object, Object, Object)

Returns an unmodifiable set containing six elements.

Of(Object, Object, Object, Object, Object, Object, Object)

Returns an unmodifiable set containing seven elements.

Of(Object, Object, Object, Object, Object, Object, Object, Object)

Returns an unmodifiable set containing eight elements.

Of(Object, Object, Object, Object, Object, Object, Object, Object, Object)

Returns an unmodifiable set containing nine elements.

Of(Object, Object, Object, Object, Object, Object, Object, Object, Object, Object)

Returns an unmodifiable set containing ten elements.

Of(Object[])

Returns an unmodifiable set containing an arbitrary number of elements.

Remove(Object)

Removes the specified element from this set if it is present (optional operation).

RemoveAll(ICollection)

Removes from this set all of its elements that are contained in the specified collection (optional operation).

RemoveIf(IPredicate)

Removes all of the elements of this collection that satisfy the given predicate.

(Inherited from ICollection)
RetainAll(ICollection)

Retains only the elements in this set that are contained in the specified collection (optional operation).

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
Size()

Returns the number of elements in this set (its cardinality).

Spliterator()

Creates a Spliterator over the elements described by this Iterable.

(Inherited from IIterable)
ToArray()

Returns an array containing all of the elements in this set.

ToArray(IIntFunction)

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

(Inherited from ICollection)
ToArray(Object[])

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Explicit Interface Implementations

IIterable.Spliterator()

Creates a Spliterator over the elements in this set.

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
ToEnumerable(IIterable)
ToEnumerable<T>(IIterable)

Applies to