Vector类

目录

所在包

All Implemented Interfaces(所有已实现接口)

Direct Known Subclasses(直接已知子类)

Field Summary(字段汇总)

Constructor Summary(构造函数的总结)

Method Summary(方法总结) 


所在包:java.util.Vector<E>

 

All Implemented Interfaces(所有已实现接口):
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
Direct Known Subclasses(直接已知子类):
Stack

 


 

public class Vector<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable
The Vector class implements a growable array of objects.
Like an array, it contains components that can be accessed using an integer index.
However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. 

Vector类实现了一个可增长的对象数组。
与数组一样,它包含可以使用整数索引访问的组件。
但是,向量的大小可以根据需要增长或收缩,以适应在创建向量之后添加和删除项。

 

Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement.

The capacity is always at least as large as the vector size; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of capacityIncrement.

An application can increase the capacity of a vector before inserting a large number of components; this reduces the amount of incremental reallocation.
每个向量都试图通过维护容量和电容增量来优化存储管理。

容量总是至少与向量大小相同;它通常更大,因为随着组件被添加到向量中,向量的存储以块的形式增加,容量增量的大小。

应用程序可以在插入大量组件之前增加向量的容量;这减少了增量重新分配的数量。

 

The iterators returned by this class's iterator and listIterator methods are fail-fast: if the vector is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException.

Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

The Enumerations returned by the elements method are not fail-fast.

这个类的iterator和listIterator方法返回的迭代器是快速失效的:如果在创建迭代器之后的任何时候,以任何方式(除了通过迭代器自己的删除或添加方法)对向量进行结构修改,迭代器将抛出ConcurrentModificationException异常。
因此,在面对并发修改时,迭代器会快速而干净地失败,而不是在将来某个不确定的时间冒任意的、不确定的行为的风险。
elements方法返回的枚举不是快速失效的。

 

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification.

Fail-fast iterators throw ConcurrentModificationException on a best-effort basis.

Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.

注意,不能保证迭代器的快速故障行为,因为通常来说,在存在非同步并发修改的情况下,不可能做出任何严格的保证。

故障快速迭代器在最大努力的基础上抛出ConcurrentModificationException。

因此,编写一个依赖于这个异常的正确性的程序是错误的:迭代器的快速故障行为应该只用于检测bug。

 

As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface, making it a member of the Java Collections Framework.

Unlike the new collection implementations, Vector is synchronized.

If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.

 

从Java 2平台v1.2开始,对该类进行了改进以实现List接口,使其成为Java集合框架的成员。
与新的集合实现不同,Vector是同步的。
如果不需要线程安全的实现,建议使用ArrayList代替Vector。

 

Since:
JDK1.0
See Also:
Collection, LinkedList, Serialized Form

Field Summary(字段汇总)

 

Modifier and Type
修饰符和类型
Field and Description
字段和描述
protected int capacityIncrement
The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity.
当向量的大小大于其容量时,向量的容量自动增加的量。
protected int elementCount
The number of valid components in this Vector object.
这个向量对象中有效分量的数量。
protected Object[] elementData
The array buffer into which the components of the vector are stored.
向量的分量存储在其中的数组缓冲区。

 

Fields inherited from class java.util.AbstractList
继承自类java.util.AbstractList的字段

modCount

 


Constructor Summary(构造函数的总结)

 

Constructor and Description
Vector()
Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.
构造一个空向量,使其内部数据数组大小为10,标准容量增量为0。
Vector(Collection<? extends E> c)
Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.
构造一个向量,其中包含指定集合的元素,按集合的迭代器返回元素的顺序排列。
Vector(int initialCapacity)
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
构造一个具有指定初始容量且其容量增量为零的空向量。
Vector(int initialCapacity, int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment.
构造具有指定初始容量和容量增量的空向量。

 


Method Summary(方法总结)

 

Modifier and Type
修饰符和类型
Method and Description
方法和描述
boolean add(E e)
Appends the specified element to the end of this Vector.
将指定的元素附加到此向量的末尾。
void add(int index, E element)
Inserts the specified element at the specified position in this Vector.
将指定元素插入到此向量的指定位置。
boolean addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator.
将指定集合中的所有元素按照指定集合的迭代器返回它们的顺序追加到此向量的末尾。
boolean addAll(int index, Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this Vector at the specified position.
将指定集合中的所有元素插入到此向量的指定位置。
void addElement(E obj)
Adds the specified component to the end of this vector, increasing its size by one.
将指定的组件添加到该向量的末尾,将其大小增加1。
int capacity()
Returns the current capacity of this vector.
返回此向量的当前容量。
void clear()
Removes all of the elements from this Vector.
从这个向量中移除所有的元素。
Object clone()
Returns a clone of this vector.
返回此向量的克隆。
boolean contains(Object o)
Returns true if this vector contains the specified element.
如果该向量包含指定的元素,则返回true。
boolean containsAll(Collection<?> c)
Returns true if this Vector contains all of the elements in the specified Collection.
如果该向量包含指定集合中的所有元素,则返回true。
void copyInto(Object[] anArray)
Copies the components of this vector into the specified array.
将此向量的组件复制到指定的数组中。
E elementAt(int index)
Returns the component at the specified index.
返回指定索引处的组件。
Enumeration<E> elements()
Returns an enumeration of the components of this vector.
返回此向量的组件的枚举。
void ensureCapacity(int minCapacity)
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
如果需要,增加这个向量的容量,以确保它至少可以容纳由最小容量参数指定的组件的数量。
boolean equals(Object o)
Compares the specified Object with this Vector for equality.
将指定的对象与此向量进行比较以确定是否相等。
E firstElement()
Returns the first component (the item at index 0) of this vector.
返回此向量的第一个组件(索引为0的项)。
void forEach(Consumer<? super E> action)
Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
为可迭代的每个元素执行给定的操作,直到处理完所有元素或操作引发异常。
E get(int index)
Returns the element at the specified position in this Vector.
返回该向量中指定位置的元素。
int hashCode()
Returns the hash code value for this Vector.
返回此向量的哈希码值。
int indexOf(Object o)
Returns the index of the first occurrence of the specified element in this vector, or -1 if this vector does not contain the element.
返回该向量中指定元素第一次出现的索引,如果该向量不包含该元素,则返回-1。
int indexOf(Object o, int index)
Returns the index of the first occurrence of the specified element in this vector, searching forwards from index, or returns -1 if the element is not found.
返回该向量中指定元素第一次出现时的索引,从索引中向前搜索;如果没有找到该元素,则返回-1。
void insertElementAt(E obj, int index)
Inserts the specified object as a component in this vector at the specified index.
在指定索引处将指定对象作为此向量中的组件插入。
boolean isEmpty()
Tests if this vector has no components.
测试这个向量是否没有成分(就是判断是否为空Vector)。
Iterator<E> iterator()
Returns an iterator over the elements in this list in proper sequence.
按适当的顺序对列表中的元素返回一个迭代器。
E lastElement()
Returns the last component of the vector.
返回向量的最后一个分量。
int lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element in this vector, or -1 if this vector does not contain the element.
返回该向量中指定元素的最后一次出现的索引,如果该向量不包含该元素,则返回-1。
int lastIndexOf(Object o, int index)
Returns the index of the last occurrence of the specified element in this vector, searching backwards from index, or returns -1 if the element is not found.
返回此向量中指定元素的最后一次出现的索引(从索引向后搜索),如果没有找到该元素,则返回-1。
ListIterator<E> listIterator()
Returns a list iterator over the elements in this list (in proper sequence).
返回该列表中元素的列表迭代器(按适当的顺序)。
ListIterator<E> listIterator(int index)
Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
返回此列表中元素的列表迭代器(按适当的顺序),从列表中的指定位置开始。
E remove(int index)
Removes the element at the specified position in this Vector.
移除此向量中指定位置的元素。
boolean remove(Object o)
Removes the first occurrence of the specified element in this Vector If the Vector does not contain the element, it is unchanged.
删除此向量中指定元素的第一个匹配项,如果该向量不包含该元素,则该元素将保持不变。
boolean removeAll(Collection<?> c)
Removes from this Vector all of its elements that are contained in the specified Collection.
从该向量中移除指定集合中包含的所有元素。
void removeAllElements()
Removes all components from this vector and sets its size to zero.
从这个向量中删除所有的分量,并将其大小设置为0。
boolean removeElement(Object obj)
Removes the first (lowest-indexed) occurrence of the argument from this vector.
从这个向量中移除第一个(索引最低的)参数。
void removeElementAt(int index)
Deletes the component at the specified index.
删除指定索引处的组件。
boolean removeIf(Predicate<? super E> filter)
Removes all of the elements of this collection that satisfy the given predicate.
删除此集合中满足给定谓词的所有元素。
protected void removeRange(int fromIndex, int toIndex)
Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
从该列表中删除其索引在包含的fromIndex和排除的toIndex之间的所有元素。
void replaceAll(UnaryOperator<E> operator)
Replaces each element of this list with the result of applying the operator to that element.
将此列表中的每个元素替换为将运算符应用于该元素的结果。
boolean retainAll(Collection<?> c)
Retains only the elements in this Vector that are contained in the specified Collection.
仅保留此向量中包含在指定集合中的元素。
E set(int index, E element)
Replaces the element at the specified position in this Vector with the specified element.
将此向量中指定位置的元素替换为指定元素。
void setElementAt(E obj, int index)
Sets the component at the specified index of this vector to be the specified object.
将此向量的指定索引处的组件设置为指定对象。
void setSize(int newSize)
Sets the size of this vector.
设置这个向量的大小。
int size()
Returns the number of components in this vector.
返回这个向量的分量数。
void sort(Comparator<? super E> c)
Sorts this list using the supplied Comparator to compare elements.
使用提供的比较器对列表进行排序,以比较元素。
Spliterator<E> spliterator()
Creates a late-binding and fail-fast Spliterator over the elements in this list.
在此列表中的元素上创建延迟绑定和故障快速Spliterator。
List<E> subList(int fromIndex, int toIndex)
Returns a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive.
返回该列表中包含的fromIndex和排除的toIndex之间部分的视图。
Object[] toArray()
Returns an array containing all of the elements in this Vector in the correct order.
返回一个数组,该数组以正确的顺序包含这个向量中的所有元素。
<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this Vector in the correct order;
the runtime type of the returned array is that of the specified array.
返回一个数组,该数组按正确的顺序包含该向量中的所有元素;
返回数组的运行时类型是指定数组的运行时类型。
String toString()
Returns a string representation of this Vector, containing the String representation of each element.
返回此向量的字符串表示形式,其中包含每个元素的字符串表示形式。
void trimToSize()
Trims the capacity of this vector to be the vector's current size.
将该向量的容量修剪为该向量的当前大小。

 


Methods inherited from class java.lang.Object
方法继承自java.lang.Object类

finalize, getClass, notify, notifyAll, wait, wait, wait

Methods inherited from interface java.util.Collection

方法继承自接口java.util.Collection

parallelStream, stream

 


 

posted @ 2020-03-25 21:36  厸清扬  阅读(338)  评论(0编辑  收藏  举报