Java Vector toArray() Method24 Mar 2025 | 3 min read The toArray() Java Vector class method is used to get an array containing all of the elements in this vector in the correct order. There is two different types of Java toArray() method which can be differentiated depending on its parameter. These are:
toArray() Method:This method is used to return an array which contains all of the elements in this vector in the correct order. toArray(T[] arr) Method:This method is used to return an array which contains all of the elements in this vector in the correct order. The runtime type of the returned array is that of the specified array. SyntaxFollowing is the declaration of toArray() method: Parameter
ReturnThe toArray() method returns an array containing all of the elements in the given collection. ExceptionsNullPointerException- This method has thrown an exception if the specified array is null. ArrayStoreException- This method has thrown an exception if the runtime type of arr, <T>, is not a supertype of the runtime type, <E>, of every element in this vector. Compatibility VersionJava 1.2 and above Example 1Output: Elements are: 1 2 3 4 5 Example 2Output: Contents of a vector are: Java Android Python COBOL Elements of the array: Java Android Python COBOL Example 3Output: The elements are: 10 30 20 40 null Next TopicJava Vector |
Java Method The get() method of Java Vector class is used to get the element at the specified position in the vector. Syntax Following is the declaration of get() method: public E get(int index) Parameter DataType Parameter Description Required/Optional int index It is an index of the element which will be returned. Required Return The get() method returns the...
2 min read
Java Method The remove() Java Vector class method is used to remove the specified element from the vector. There are two different types of Java remove() method which can be differentiated depending on its parameter. These are: Java Vector remove(int index) Method Java Vector remove(Object o) Method remove(int...
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 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 equals() method of Java Vector class used to compare the specified object with this Vector for equality. It returns true if and only if the specified object is also a list, both lists have the same size and all corresponding pairs of...
2 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 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 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 setSize() method of Java Vector class is used to set the size of a vector. If the new size is greater than the current size, null items are added to the end of the vector. Otherwise, all components at index newSize and...
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
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