Java Vector forEach() Method24 Mar 2025 | 1 min read 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 is specified. Syntax:Following is the declaration of forEach() method: Parameter:
Returns:The forEach() method does not return anything. It only performs the given action for each element. Exceptions:NullPointerException- This method has thrown an exception if the specified action is null. Compatibility Version:Java 1.2 and above Example 1:Output: 1 2 3 4 5 Example 2:Output: White Green Black Pink Next TopicJava Vector |
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 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 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 clone() method of Java Vector class is used to get a clone of the vector which is in use. Syntax: Following is the declaration of clone() method: Public object clone() Parameter: This method does not accept any parameter. Returns: This method returns a clone of the vector which is...
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 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 indexOf() Java Vector class method is used to get the index of the first occurrence of the specified element in the vector. There are two different types of Java indexOf() method which can be differentiated depending on its parameter. These are: Java Vector...
3 min read
Java Method The removeElementAt() method of Java Vector class is used to delete the component at the specified index. Each element in this vector with an index greater or equal to the given index is shifted downward. Now the vector index is one smaller than...
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
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