Java Vector elementAt() Method24 Mar 2025 | 2 min read The elementAt() method of Java Vector class is used to get the element at the specified index in the vector. SyntaxFollowing is the declaration of elementAt() method: Parameter
ReturnThe elementAt() method returns an element at the specified index. ExceptionsArrayIndexOutOfBoundsException- This method has thrown an exception if the index is out of range i.e. index < 0 || index >= size(). Compatibility VersionJava 1.2 and above Example 1Output: Element at index 1 is = 2 Element at index 3 is = 4 Example 2Output: Element at 0th position = White Element at 2nd position = Black Example 3Output: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 >= 3 at java.base/java.util.Vector.elementAt(Vector.java:496) at myPackage.VectorElementAtExample3.main(VectorElementAtExample3.java:12) Next TopicJava Vector |
Java Method The copyInto() method of Java Vector class used to copy the elements of the vector which is in use into the specified array. In this, the position of the elements is the same in both the vector and an array. Syntax: Following is the declaration...
3 min read
Java Method The addElement() method of Java Vector class is used to add the specified element to the end of this vector. Adding an element increases the vector size by one. Syntax: Following is the declaration of addElement() method: Public void addElement(E e) Parameter: Parameter Description Required/Optional e It is the element which will...
2 min read
Java Method The size() method of Java Vector class is used to get the number of components presents in the vector. Syntax Following is the declaration of size() method: public int size() Parameter This method does not accept any parameter. Return The size() method returns the number of components presents in a...
2 min read
Java Method The addAll() Java Vector class method inserts all of the elements in the specified collection to the end of the vector which is in use. The order of the elements will be the same as they are returned by the specified collection's iterator....
5 min read
Java Method The set() method of Java Vector class is used to replace the element at the specified position in the vector with the specified element. Syntax Following is the declaration of set() method: Public E set(int index, E element) Parameter Parameter Description Required/Optional index It is an index of the element which will...
2 min read
Java Method The lastElement() method of Java Vector class is used to get the last component of the vector. Syntax Following is the declaration of lastElement() method: Public E lastElement() Parameter This method does not accept any parameter. Return The lastElement() method returns the last element of the vector i.e. the component...
2 min read
Java Method The ensureCapacity() method of Java Vector class is used to increase the capacity of the vector which is in use, if necessary. It ensures that the vector can hold at least the number of components specified by the minimum capacity argument. Syntax: Following is the...
2 min read
Java Method The forEach() method of Java Vector class is used to perform the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration if that order...
2 min read
Java Method The firstElement() method of Java Vector class is used to get the first element ( at index 0 ) of the vector which is in use. Syntax: Following is the declaration of firstElement() method: public E firstElement() Parameter: This method does not accept any parameter. Returns: The firstElement() method returns...
2 min read
Java Method The toString() method of Java Vector class is used to get a string representation of the vector. It contains the string representation of each element. Syntax Following is the declaration of toString() method: public String toString() Parameter This method does not accept any parameter. Return The toString() method returns a...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India