Partager via


IList Interface

Definition

An ordered collection (also known as a sequence).

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

Remarks

An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.

Unlike sets, lists typically allow duplicate elements. More formally, lists typically allow pairs of elements e1 and e2 such that e1.equals(e2), and they typically allow multiple null elements if they allow null elements at all. It is not inconceivable that someone might wish to implement a list that prohibits duplicates, by throwing runtime exceptions when the user attempts to insert them, but we expect this usage to be rare.

The List interface places additional stipulations, beyond those specified in the Collection interface, on the contracts of the iterator, add, remove, equals, and hashCode methods. Declarations for other inherited methods are also included here for convenience.

The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example). Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.

The List interface provides a special iterator, called a ListIterator, that allows element insertion and replacement, and bidirectional access in addition to the normal operations that the Iterator interface provides. A method is provided to obtain a list iterator that starts at a specified position in the list.

The List interface provides two methods to search for a specified object. From a performance standpoint, these methods should be used with caution. In many implementations they will perform costly linear searches.

The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list.

Note: While it is permissible for lists to contain themselves as elements, extreme caution is advised: the equals and hashCode methods are no longer well defined on such a list.

Some list 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 list 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 Lists</h2>

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

<ul> <li>They are <i>unmodifiable</i>. Elements cannot be added, removed, or replaced. Calling any mutator method on the List will always cause UnsupportedOperationException to be thrown. However, if the contained elements are themselves mutable, this may cause the List's 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>The order of elements in the list is the same as the order of the provided arguments, or of the elements in the provided array. <li>The lists and their #subList(int, int) subList views implement the RandomAccess interface. <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>

Added in 1.2.

Java documentation for java.util.List.

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 whether this List contains 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(Int32, Object)

Inserts the specified element at the specified position in this list (optional operation).

Add(Object)

Appends the specified element to the end of this list (optional operation).

AddAll(ICollection)

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

AddAll(Int32, ICollection)

Inserts all of the elements in the specified collection into this list at the specified position (optional operation).

Clear()

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

Contains(Object)

Returns true if this list contains the specified element.

ContainsAll(ICollection)

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

CopyOf(ICollection)

Returns an unmodifiable List containing the elements of the given Collection, in its iteration order.

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 list 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)
Get(Int32)

Returns the element at the specified position in this list.

GetHashCode()

Returns the hash code value for this list.

IndexOf(Object)

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

Iterator()

Returns an iterator over the elements in this list in proper sequence.

LastIndexOf(Object)

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.

ListIterator()

Returns a list iterator over the elements in this list (in proper sequence).

ListIterator(Int32)

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.

Of()

Returns an unmodifiable list containing zero elements.

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

Returns an unmodifiable list containing ten elements.

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

Returns an unmodifiable list containing nine elements.

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

Returns an unmodifiable list containing eight elements.

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

Returns an unmodifiable list containing seven elements.

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

Returns an unmodifiable list containing six elements.

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

Returns an unmodifiable list containing five elements.

Of(Object, Object, Object, Object)

Returns an unmodifiable list containing four elements.

Of(Object, Object, Object)

Returns an unmodifiable list containing three elements.

Of(Object, Object)

Returns an unmodifiable list containing two elements.

Of(Object)

Returns an unmodifiable list containing one element.

Of(Object[])

Returns an unmodifiable list containing an arbitrary number of elements.

Remove(Int32)

Removes the element at the specified position in this list (optional operation).

Remove(Object)

Removes the first occurrence of the specified element from this list, if it is present (optional operation).

RemoveAll(ICollection)

Removes from this list 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)
ReplaceAll(IUnaryOperator)

Replaces each element of this list with the result of applying the operator to that element.

RetainAll(ICollection)

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

Set(Int32, Object)

Replaces the element at the specified position in this list with the specified element (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 list.

Sort(IComparator)

Sorts this list according to the order induced by the specified Comparator.

Spliterator()

Creates a Spliterator over the elements described by this Iterable.

(Inherited from IIterable)
SubList(Int32, Int32)

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.

ToArray()

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

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 list in proper sequence (from first to last element); 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 list.

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

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

Applies to