- Java.util - WeakHashMap
- Java.util - Vector
- Java.util - UUID
- Java.util - TreeSet
- Java.util - TreeMap
- Java.util - TimeZone
- Java.util - TimerTask
- Java.util - Timer
- Java.util - StringTokenizer
- Java.util - Stack
- Java.util - SimpleTimeZone
- Java.util - ServiceLoader
- Java.util - Scanner
- Java.util - ResourceBundle.Control
- Java.util - ResourceBundle
- Java.util - Random
- Java.util - PropertyResourceBundle
- Java.util - PropertyPermission
- Java.util - Properties
- Java.util - PriorityQueue
- Java.util - Observable
- Java.util - Locale
- Java.util - ListResourceBundle
- Java.util - LinkedList
- Java.util - LinkedHashSet
- Java.util - LinkedHashMap
- Java.util - IdentityHashMap
- Java.util - Hashtable
- Java.util - HashSet
- Java.util - HashMap
- Java.util - GregorianCalendar
- Java.util - Formatter
- Java.util - EnumSet
- Java.util - EnumMap
- Java.util - Dictionary
- Java.util - Date
- Java.util - Currency
- Java.util - Collections
- Java.util - Calendar
- Java.util - BitSet
- Java.util - Arrays
- Java.util - ArrayList
- Java.util - ArrayDeque
- Java.util - Home
Java.util Package Extras
- Java.util - Discussion
- Java.util - Useful Resources
- Java.util - Enumerations
- Java.util - Exceptions
- Java.util - Interfaces
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java.util.Vector Class
Introduction
The java.util.Vector class implements a growable array of objects. Similar to an Array, it contains components that can be accessed using an integer index. Following are the important points about Vector −
The size of a Vector can grow or shrink as needed to accommodate adding and removing items.
Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement.
As of the Java 2 platform v1.2, this class was retrofitted to implement the List interface.
Unpke the new collection implementations, Vector is synchronized.
This class is a member of the Java Collections Framework.
Class declaration
Following is the declaration for java.util.Vector class −
pubpc class Vector<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Seriapzable
Here <E> represents an Element, which could be any class. For example, if you re building an array pst of Integers then you d initiapze it as follows −
ArrayList<Integer> pst = new ArrayList<Integer>();
Class constructors
Sr.No. | Constructor & Description |
---|---|
1 | Vector() This constructor is used to create 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) This constructor is used to create a vector containing the elements of the specified collection, in the order they are returned by the collection s iterator. |
3 | Vector(int initialCapacity) This constructor is used to create an empty vector with the specified initial capacity and with its capacity increment equal to zero. |
4 | Vector(int initialCapacity, int capacityIncrement) This constructor is used to create an empty vector with the specified initial capacity and capacity increment. |
Class methods
Sr.No. | Method & Description |
---|---|
1 | This method appends the specified element to the end of this Vector. |
2 | This method inserts the specified element at the specified position in this Vector. |
3 | This method appends all of the elements in the specified Collection to the end of this Vector. |
4 | This method inserts all of the elements in the specified Collection into this Vector at the specified position. |
5 | This method adds the specified component to the end of this vector, increasing its size by one. |
6 | This method returns the current capacity of this vector. |
7 | This method removes all of the elements from this vector. |
8 | This method returns a clone of this vector. |
9 | This method returns true if this vector contains the specified element. |
10 | This method returns true if this Vector contains all of the elements in the specified Collection. |
11 | This method copies the components of this vector into the specified array. |
12 | This method returns the component at the specified index. |
13 | This method returns an enumeration of the components of this vector. |
14 | This method 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 | This method compares the specified Object with this Vector for equapty. |
16 | This method returns the first component (the item at index 0) of this vector. |
17 | This method returns the element at the specified position in this Vector. |
18 | This method returns the hash code value for this Vector. |
19 | This method returns the index of the first occurrence of the specified element in this vector, or -1 if this vector does not contain the element. |
20 | This method 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. |
21 | This method inserts the specified object as a component in this vector at the specified index. |
22 | This method tests if this vector has no components. |
23 | This method returns the last component of the vector. |
24 | This method returns the index of the last occurrence of the specified element in this vector, or -1 if this vector does not contain the element. |
25 | This method 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. |
26 | This method removes the element at the specified position in this Vector. |
27 | This method removes the first occurrence of the specified element in this Vector If the Vector does not contain the element, it is unchanged. |
28 | This method removes from this Vector all of its elements that are contained in the specified Collection. |
29 | This method removes all components from this vector and sets its size to zero. |
30 | This method removes the first occurrence of the argument from this vector. |
31 | This method deletes the component at the specified index. |
32 | This method removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. |
33 | This method retains only the elements in this Vector that are contained in the specified Collection. |
34 | This method replaces the element at the specified position in this Vector with the specified element. |
35 | This method sets the component at the specified index of this vector to be the specified object. |
36 | This method sets the size of this vector. |
37 | This method returns the number of components in this vector. |
38 | This method returns a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive. |
39 | This method returns an array containing all of the elements in this Vector in the correct order. |
40 | This method 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. |
41 | This method returns a string representation of this Vector, containing the String representation of each element. |
42 | This method trims the capacity of this vector to be the vector s current size. |
Methods inherited
This class inherits methods from the following classes −
java.util.AbstractMap
java.lang.Object
java.util.List