|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure5.AbstractStructure<E> structure5.AbstractList<E> structure5.Vector<E>
public class Vector<E>
An implementation of extensible arrays, similar to that of java.util.Vector
.
This vector class implements a basic extensible array. It does not implement
any of the additional features of the Sun class, including list-like operations.
Those operations are available in other implementors of List
in this
package.
Example usage: To put a program's parameters into a Vector, we would use the following:
public static void main(String[] arguments) {Vector<String>
argVec = newVector<String>()
; for (int i = 0; i < arguments.length; i++) { argVec.add(arguments[i])
; } System.out.println(argVec
); }
Constructor Summary | |
---|---|
Vector()
Construct an empty vector. |
|
Vector(Collection<E> c)
|
|
Vector(int initialCapacity)
Construct an empty vector capable of storing initialCapacity
values before the vector must be extended. |
|
Vector(int initialCapacity,
int capacityIncr)
Construct a vector with initial capacity, and growth characteristic. |
|
Vector(int initialCapacity,
int capacityIncr,
E initValue)
Construct a vector with initial size, growth rate and default value. |
|
Vector(Vector<E> that)
|
Method Summary | |
---|---|
void |
add(E obj)
Add an element to the high end of the array, possibly expanding vector. |
void |
add(int index,
E obj)
Insert an element at a particular location. |
void |
addElement(E o)
Add an element to the high end of the array, possibly expanding vector. |
int |
capacity()
Determine the capacity of the vector. |
void |
clear()
Remove all the values of the vector. |
Object |
clone()
Construct a shallow copy of the vector. |
boolean |
contains(E elem)
Determine if a value appears in a vector. |
void |
copyInto(Object[] dest)
Copy the contents of the vector into an array. |
E |
elementAt(int index)
Fetch the element at a particular index. |
void |
ensureCapacity(int minCapacity)
Ensure that the vector is capable of holding at least minCapacity values without expansion. |
E |
firstElement()
Get access to the first element of the vector. |
E |
get(int index)
Fetch the element at a particular index. |
int |
indexOf(E elem)
Assuming the data is not in order, find the index of a value, or return -1 if not found. |
int |
indexOf(E elem,
int index)
Assuming the data is not in order, find the index of a value or return -1 if the value is not found. |
void |
insertElementAt(E obj,
int index)
Insert an element at a particular location. |
boolean |
isEmpty()
Determine if the Vector contains no values. |
Iterator<E> |
iterator()
Construct a iterator over the elements of the vector. |
E |
lastElement()
Fetch a reference to the last value in the vector. |
int |
lastIndexOf(E obj)
Search for the last occurrence of a value within the vector. |
int |
lastIndexOf(E obj,
int index)
Find the index of the last occurrence of the value in the vector before the indexth position. |
E |
remove(E element)
Remove an element, by value, from vector. |
E |
remove(int where)
Remove an element at a particular location. |
void |
removeAllElements()
Remove all the elements of the vector. |
void |
removeElementAt(int where)
Remove an element at a particular location. |
E |
set(int index,
E obj)
Change the value stored at location index. |
void |
setElementAt(E obj,
int index)
Change the value stored at location index. |
void |
setSize(int newSize)
Explicitly set the size of the array. |
int |
size()
Determine the number of elements in the vector. |
String |
toString()
Determine a string representation for the vector. |
void |
trimToSize()
Trim the vector to exactly the correct size. |
Methods inherited from class structure5.AbstractList |
---|
addFirst, addLast, get, getFirst, getLast, remove, removeFirst, removeLast |
Methods inherited from class structure5.AbstractStructure |
---|
elements, hashCode, values |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure5.Structure |
---|
elements, values |
Constructor Detail |
---|
public Vector()
public Vector(int initialCapacity)
initialCapacity
values before the vector must be extended.
initialCapacity
- The size of vector before reallocation is necessarypublic Vector(int initialCapacity, int capacityIncr)
initialCapacity
- The initial number of slots in vector.capacityIncr
- The size of growth of vector.capacityIncrement
public Vector(int initialCapacity, int capacityIncr, E initValue)
initialCapacity
- The initial number of slots in vector.capacityIncr
- The size of the increment when vector grows.initValue
- The initial value stored in vector elements.public Vector(Vector<E> that)
public Vector(Collection<E> c)
Method Detail |
---|
public void ensureCapacity(int minCapacity)
minCapacity
- The minimum size of array before expansion.public void add(E obj)
add
in interface List<E>
add
in interface Structure<E>
add
in class AbstractList<E>
obj
- The object to be added to the end of the vector.AbstractList.addLast(E)
public void addElement(E o)
obj
- The object to be added to the end of the vector.public E remove(E element)
remove
in interface List<E>
remove
in interface Structure<E>
element
- the element to be removed.
public int capacity()
public Object clone()
clone
in class Object
public boolean contains(E elem)
contains
in interface List<E>
contains
in interface Structure<E>
contains
in class AbstractList<E>
elem
- The value sought.
public void copyInto(Object[] dest)
dest
- An array of size at least size().public E elementAt(int index)
index
- The index of the value sought.
public E get(int index)
get
in interface List<E>
index
- The index of the value sought.
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface List<E>
iterator
in interface Structure<E>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public E firstElement()
public int indexOf(E elem)
indexOf
in interface List<E>
elem
- The value sought in vector.
public int indexOf(E elem, int index)
elem
- The value sought.index
- The first location considered.
public void insertElementAt(E obj, int index)
obj
- The value to be inserted.index
- The location of the new value.public void add(int index, E obj)
add
in interface List<E>
obj
- the value to be inserted.index
- the location of the new value.public boolean isEmpty()
isEmpty
in interface List<E>
isEmpty
in interface Structure<E>
isEmpty
in class AbstractList<E>
public E lastElement()
public int lastIndexOf(E obj)
lastIndexOf
in interface List<E>
obj
- The value sought.
public int lastIndexOf(E obj, int index)
obj
- The value sought.index
- The last acceptable index.
public void clear()
clear
in interface List<E>
clear
in interface Structure<E>
public void removeAllElements()
clear()
public void removeElementAt(int where)
where
- The location of the element to be removed.public E remove(int where)
remove
in interface List<E>
where
- The location of the element to be removed.
public void setElementAt(E obj, int index)
obj
- The new value to be stored.index
- The index of the new value.public E set(int index, E obj)
set
in interface List<E>
obj
- The new value to be stored.index
- The index of the new value.
public void setSize(int newSize)
newSize
- The ultimate size of the vector.public int size()
size
in interface List<E>
size
in interface Structure<E>
public void trimToSize()
public String toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |