Java数据结构-List(二)
来源:互联网 发布:小意思托福 mac 编辑:程序博客网 时间:2024/05/23 12:46
A List
is a collection which maintains an ordering for its elements. Every element in the List
has an index. Each element can thus be accessed by its index, with the first index being zero. Normally, List
s allow duplicate elements, as compared to Sets, where elements have to be unique.
List接口实现Collection接口,可以在其中保持元素的顺序。每一个List中的元素都有一个角标(index),角标从0开始,可以通过角标来访问元素。通常List允许其元素重复,而Set中的元素必须唯一。
在通过角标来访问List的元素的过程中,如果角标超过了List的角标范围,将会抛出角标越界异常(IndexOutOfBoundsException)。
List的子类:
除了继承自Collection接口的方法之外,List主要添加了一些通过角标进行元素操作的方法。
public abstract boolean add (E object)
Adds the specified object at the end of this List
.
public abstract void add (int location, E object)
Inserts the specified object into this List
at the specified location. The object is inserted before the current element at the specified location. If the location is equal to the size of this List
, the object is added at the end. If the location is smaller than the size of this List
, then all elements beyond the specified location are moved by one position towards the end of the List
.
在指定的位置添加特定对象。对象将被添加到当前指定位置的元素的前面。如果指定的位置等于List的大小,那么对象将被添加到List的尾部。如果指定的位置小于List的大小,那么所有处于该位置后面的元素都将会向后一次移动一个位置。如果指定的位置大于List的大小,那么将会抛出角标越界异常(IndexOutOfBoundsException)。
Parameters
Throws
List
is not supported.List
.List
.location < 0 || location > size()
public abstract E get (int location)
Returns the element at the specified location in this List
.
返回指定位置的元素。
Parameters
Returns
- the element at the specified location.
Throws
location < 0 || location >= size()
public abstract int indexOf (Object object)
Searches this List
for the specified object and returns the index of the first occurrence.
返回第一个符合指定对象的元素的角标。如果没有找到符合该对象的元素,将会返回-1。
Parameters
Returns
- the index of the first occurrence of the object or -1 if the object was not found.
public abstract int lastIndexOf (Object object)
Searches this List
for the specified object and returns the index of the last occurrence.
返回最后一个符合指定对象的元素的角标。如果没有找到符合该对象的元素,将会返回-1。
Parameters
Returns
- the index of the last occurrence of the object, or -1 if the object was not found.
public abstract ListIterator<E> listIterator (int location)
Returns a list iterator on the elements of this List
. The elements are iterated in the same order as they occur in the List
. The iteration starts at the specified location.
返回一个基于该List元素的ListIterator。该Iterator从指定位置开始,其顺序与List中的元素顺序一致。
Parameters
Returns
- a list iterator on the elements of this
List
.
Throws
location < 0 || location > size()
See Also
ListIterator
public abstract ListIterator<E> listIterator ()
Returns a List
iterator on the elements of this List
. The elements are iterated in the same order that they occur in the List
.
Returns
- a
List
iterator on the elements of thisList
See Also
ListIterator
public abstract E set (int location, E object)
Replaces the element at the specified location in this List
with the specified object. This operation does not change the size of the List
.
替换指定位置上的元素。该操作不会改变List的大小,只会将指定位置上的元素替换为给定的对象。
Parameters
Returns
- the previous element at the index.
Throws
List
is not supported.List
.List
.location < 0 || location >= size()
public abstract List<E> subList (int start, int end)
Returns a List
of the specified portion of this List
from the given start index to the end index minus one. The returned List
is backed by this List
so changes to it are reflected by the other.
返回当前List的一部分,从给定的起始角标到结束角标的前一位(即不包括结束角标的元素)。
Parameters
Returns
- a list of a portion of this
List
.
Throws
start < 0, start > end
or end > size()
- Java数据结构-List(二)
- Java数据结构详解(二)-List接口
- Java大课堂:常用数据结构二(List)
- Redis数据结构详解之List(二)
- Redis数据结构详解之List(二)
- Redis数据结构详解之List(二)
- 【二】数据结构之List
- 数据结构之“Ordered List and Sorted List”(二)
- JAVA 容器(二)----List
- java(19):数据结构(2)--List
- java数据结构-List
- java数据结构之List
- java中的数据结构--list
- Java 数据结构List
- java数据结构-List
- java数据结构-List
- 自己动手,实现一种类似List<T>的数据结构(二)
- Python数据结构(二)序列类型list,tuple
- Java内部类详解
- 线程对象不能多次调用start函数开辟线程
- poj 3254(状态压缩dp)
- 浩易南:劳心者治人,劳力者治于人
- 开始打破常规5
- Java数据结构-List(二)
- 链接二三事
- 黑马程序员---HTML与JS学习笔记
- ParaviewWeb学习记录6——模型颜色问题2
- bzoj-1878 HH的项链
- time stamp log function test with variable argument
- 1.1 Abstract Factory(抽象工厂) -- 对象创建型模式
- Database Incarnations
- L脚本语言编写的简单数学函数库