Java – Vector Class

Java Vector Class methods, constructors, variables available in Java 8 release are listed below. We will publish example program on each methods ASAP.

Variables in Java Vector Class

S.No Variable & Description
1 protected int capacityIncrement

The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity.
2 protected int elementCount

The number of valid components in this Vector object.
3 protected Object[] elementData

The array buffer into which the components of the vector are stored.

Constructors in Java Vector Class

S.No Constructor & Description
1 Vector()

Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.
2 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.
3 Vector(int initialCapacity)

Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
4 Vector(int initialCapacity, int capacityIncrement)

Constructs an empty vector with the specified initial capacity and capacity increment.

Methods in Java Vector Class

S.No Method & Description
1 boolean add(E e)

Appends the specified element to the end of this Vector.
2 void add(int index, E element)

Inserts the specified element at the specified position in this Vector.
3 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.
4 boolean addAll(int index, Collection<? extends E> c)

Inserts all of the elements in the specified Collection into this Vector at the specified position.
5 void addElement(E obj)

Adds the specified component to the end of this vector, increasing its size by one.
6 int capacity()

Returns the current capacity of this vector.
7 void clear()

Removes all of the elements from this Vector.
8 Object clone()

Returns a clone of this vector.
9 boolean contains(Object o)

Returns true if this vector contains the specified element.
10 boolean containsAll(Collection<?> c)

Returns true if this Vector contains all of the elements in the specified Collection.
11 void copyInto(Object[] anArray)

Copies the components of this vector into the specified array.
12 E elementAt(int index)

Returns the component at the specified index.
13 Enumeration<E> elements()

Returns an enumeration of the components of this vector.
14 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.
15 boolean equals(Object o)

Compares the specified Object with this Vector for equality.
16 E firstElement()

Returns the first component (the item at index 0) of this vector.
17 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.
18 E get(int index)

Returns the element at the specified position in this Vector.
19 int hashCode()

Returns the hash code value for this Vector.
20 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.
21 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.
22 void insertElementAt(E obj, int index)

Inserts the specified object as a component in this vector at the specified index.
23 boolean isEmpty()

Tests if this vector has no components.
24 Iterator<E> iterator()

Returns an iterator over the elements in this list in proper sequence.
25 E lastElement()

Returns the last component of the vector.
26 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.
27 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.
28 ListIterator<E> listIterator()

Returns a list iterator over the elements in this list (in proper sequence).
29 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.
30 E remove(int index)

Removes the element at the specified position in this Vector.
31 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.
32 boolean removeAll(Collection<?> c)

Removes from this Vector all of its elements that are contained in the specified Collection.
33 void removeAllElements()

Removes all components from this vector and sets its size to zero.
34 boolean removeElement(Object obj)

Removes the first (lowest-indexed) occurrence of the argument from this vector.
35 void removeElementAt(int index)

Deletes the component at the specified index.
36 boolean removeIf(Predicate<? super E> filter)

Removes all of the elements of this collection that satisfy the given predicate.
37 protected void removeRange(int fromIndex, int toIndex)

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
38 void replaceAll(UnaryOperator<E> operator)

Replaces each element of this list with the result of applying the operator to that element.
39 boolean retainAll(Collection<?> c)

Retains only the elements in this Vector that are contained in the specified Collection.
40 E set(int index, E element)

Replaces the element at the specified position in this Vector with the specified element.
41 void setElementAt(E obj, int index)

Sets the component at the specified index of this vector to be the specified object.
42 void setSize(int newSize)

Sets the size of this vector.
43 int size()

Returns the number of components in this vector.
44 void sort(Comparator<? super E> c)

Sorts this list according to the order induced by the specified Comparator.
45 Spliterator<E> spliterator()

Creates a late-binding and fail-fast Spliterator over the elements in this list.
46 List<E> subList(int fromIndex, int toIndex)

Returns a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive.
47 Object[] toArray()

Returns an array containing all of the elements in this Vector in the correct order.
48 <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.
49 String toString()

Returns a string representation of this Vector, containing the String representation of each element.
50 void trimToSize()

Trims the capacity of this vector to be the vector’s current size.

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java ArrayList retainAll() method with example
  2. Java – Iterator Interface
  3. Java – PrimitiveIterator.OfDouble Interface
  4. Java – ArrayBlockingQueue Class
  5. Java – Spliterator.OfInt Interface
  6. Java – LongAdder Class
  7. Java – ReentrantReadWriteLock Class
  8. Java – ToDoubleFunction Interface
  9. java.util.concurrent Package
  10. Java – List Interface
  11. Java – LongAccumulator Class
  12. Java ArrayList toArray() method with example
  13. Java – IdentityHashMap Class
  14. Java – LongFunction Interface
  15. Java – ToIntBiFunction Interface

Be the first to comment

Leave a Reply