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 lastIndexOf() Java Vector class method is used to get the index of the last occurrence of the specified element in the vector. There are two different types of Java lastIndexOf() method which can be differentiated depending on its parameter. These are: Java Vector...
3 min read
Java Method The replaceAll() method of Java Vector class is used to replace each element of the list with the result of applying the operator to that element. Syntax Following is the declaration of replaceAll() method: public void replaceAll(UnaryOperator<E> operator) Parameter Parameter Description Required/Optional operator It is an operator which will apply to each...
2 min read
Java Method The contains() method of Java Vector class is used to check the vector which is in use contains the specified element or not. It returns true if this vector contains the specified element, otherwise returns false. Syntax: Following is the declaration of contains() method: public boolean...
2 min read
Java Method The setElementAt() method of Java Vector class is used to replace the component at the specified index of this vector to be the specified object. Syntax Following is the declaration of setElementAt() method: public void setElementAt(E obj, int index) Parameter Parameter Description Required/Optional index It is the specified index where an element...
2 min read
Java Method The removeElement() method of Java Vector class is used to remove the first (lowest-indexed) occurrence of the argument from this vector. Removing an element decreases the vector size by one. Syntax Following is the declaration of removeElement() method: Public boolean removeElement(Object obj) Parameter Parameter Description Required/Optional obj It is an element which...
2 min read
Java Method The isEmpty() method of Java Vector class is used to check if this vector has no components. It returns true if the vector is empty, otherwise returns false. Syntax Following is the declaration of isEmpty() method: Public boolean isEmpty() Parameter This method does not accept any parameter. Return The isEmpty()...
3 min read
Java Method The hashCode() method of Java Vector class is used to get the hashcode value for the vector which is in use. Syntax: Following is the declaration of hashCode() method: public int hashCode() Parameter: This method does not accept any parameter. Returns: The hashCode() method returns the hash code value for...
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 listIterator() Java Vector class method returns a list iterator over the elements in the given list in a proper sequence. There is two different types of Java listIterator() method which can be differentiated depending on its parameter. These are: Java Method Java Vector...
4 min read
Java Method The spliterator() method of Java Vector class is used to create a late-binding and fail-fast spliterator over the elements in this list. Syntax Following is the declaration of spliterator() method: public Spliterator<E> spliterator() Parameter This method does not accept any parameter. Return The spliterator() method returns a spliterator over the...
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