Each vector tries to optimize storage management by maintaining a {@code capacity} and a {@code capacityIncrement}. The {@code capacity} is always at least as large as the vectorsize; it is usually larger because as components are added to the vector, the vector's storage increases in chunks the size of {@code 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 Vector'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 Vector's elements method are not fail-fast.
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 {@code 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.
As of the Java 2 platform v1.2, this class was retrofitted to implement the {@link List} interface, making it a member of the Java Collections Framework. Unlike the new collection implementations, {@code Vector} is synchronized. @author Lee Boynton @author Jonathan Payne @version 1.106, 06/16/06 @see Collection @see List @see ArrayList @see LinkedList @since JDK1.0
double
s in an array, and is used alongside Matrix
in numerical computations. Implementing classes decides on the actual storage. Use size
to get the vector size. get(int)
gets an element, and there are corresponding set(int,double)
and add(int,double)
methods as well. Note that vector indices are zero-based (typical for Java and C). This means that they range from 0 to size-1
. It is legal to have size
equal zero.
Other basic operations are zero
which zeros all the entries of the vector, which can be cheaper than either zeroing the vector manually, or creating a new vector, and the operation copy
which creates a deep copy of the vector. This copy has separate storage, but starts with the same contents as the current vector.
The vector interface extends Iterable
, and the iterator returns a VectorEntry
which contains current index and entry value. Note that the iterator may skip non-zero entries. Using an iterator, many simple and efficient algorithms can be created. The iterator also permits changing values in the vector, however only non-zero entries can be changed.
A selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.
The operations available include:
clone()
in order to get a copy.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|