Java Vector firstElement() Method24 Mar 2025 | 2 min read 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: Parameter:This method does not accept any parameter. Returns:The firstElement() method returns the first component of the vector which is in use. Exceptions:NoSuchElementException- This method has thrown an exception if the vector has an empty element. Compatibility Version:Java 1.2 and above Example 1:Output: First element of the vector is = 91 Example 2:Output: First color of this vector = White Example 3:Output: Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Vector.firstElement(Vector.java:511) at myPackage.VectorFirstElementExample3.main(VectorFirstElementExample3.java:8) Next TopicJava Vector |
Java Method The trimToSize() method of Java Vector class is used to trim the capacity of the vector to be the vector's current size. An application can use this operation to minimize the storage of a vector. Syntax Following is the declaration of trimToSize() method: public void trimToSize() Parameter This...
3 min read
Java Method The subList() method of Java Vector class is used to get a view of the portion of the list between fromIndex, inclusive, and toIndex, exclusive. If fromIndex and toIndex are equal, the returned List is empty. Syntax Following is the declaration of subList() method: Public List<E>...
3 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 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 capacity() method of Java Vector class is used to get the current capacity of the vector which is in use. Syntax: Following is the declaration of capacity() method: Public int capacity() Parameter: This method does not accept any parameter. Returns: This method returns the current capacity of the vector...
2 min read
Java Method The removeAllElements() method of Java Vector class is used to remove all elements from the vector and set the size of the vector to zero. Syntax Following is the declaration of removeAllElements() method: Public void removeAllElements() Parameter This method does not accept any parameter. Return This method has return type...
2 min read
Java Method The sort() method of Java Vector class is used to sort the vector according to the order induced by the specified Comparator. Syntax Following is the declaration of a sort() method: Public void sort(Comparator<? super E> c) Parameter Parameter Description Required/Optional c It is the Comparator which is used to compare vector...
3 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
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 removeAll() method of Java Vector class deletes all the elements from the vector that are present in the specified collection. Syntax Following is the declaration of removeAll() method: public boolean removeAll(Collection<?> c) Parameter Parameter Description Required/Optional c It is a collection of elements which will be removed from the vector. Required Return The removeAll()...
3 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