IList.SubList(Int32, Int32) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a view of the portion of this list between the specified
fromIndex
, inclusive, and toIndex
, exclusive.
[Android.Runtime.Register("subList", "(II)Ljava/util/List;", "GetSubList_IIHandler:Java.Util.IListInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public System.Collections.IList SubList (int fromIndex, int toIndex);
[<Android.Runtime.Register("subList", "(II)Ljava/util/List;", "GetSubList_IIHandler:Java.Util.IListInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member SubList : int * int -> System.Collections.IList
Parameters
- fromIndex
- Int32
low endpoint (inclusive) of the subList
- toIndex
- Int32
high endpoint (exclusive) of the subList
Returns
a view of the specified range within this list
- Attributes
Exceptions
if start end
or end >
size()
Remarks
Returns a view of the portion of this list between the specified fromIndex
, inclusive, and toIndex
, exclusive. (If fromIndex
and toIndex
are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.
This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:
{@code
list.subList(from, to).clear();
}
Similar idioms may be constructed for indexOf
and lastIndexOf
, and all of the algorithms in the Collections
class can be applied to a subList.
The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)
Java documentation for java.util.List.subList(int, int)
.
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.