toArray(): This method is available in java.util.Vector class of Java.
Syntax:
Object[] java.util.Vector.toArray()
This method returns an array containing all of the elements in this Vector in the correct order.
Parameters: NA
Returns: an array containing all of the elements in this list in proper sequence.
Exceptions: NA
Approach
Java
import java.util.Arrays;import java.util.Vector;public class VectortoArray {public static void main(String[] args) {Vector<String> vector = new Vector<>();vector.add("Hello");vector.add("Java");vector.add("C++");vector.add("Program");System.out.println(Arrays.toString(vector.toArray()));}}
Output:
[Hello, Java, C++, Program]
No comments:
Post a Comment