Convert Vector to Array

Object[] toArray()
Returns an array containing all of the elements in this Vector in the correct order.
<T> T[] toArray(T[] a)
Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.
String toString()
Returns a string representation of this Vector, containing the String representation of each element.

import java.util.Arrays;
import java.util.Vector;

public class Main{

  public static void main(String args[]) {

    Vector v = new Vector();

    v.add("java2s.com");
    v.add("A");
    v.add("B");
    
    Object[] arr = v.toArray();

    System.out.println(Arrays.toString(arr));
  }
}

The output:


[java2s.com, A, B]
Home 
  Java Book 
    Collection  

Vector:
  1. Vector class
  2. Create Vector objects
  3. Add elements to this vector
  4. Size and capacity
  5. Remove all elements from a vector
  6. Clone a vector
  7. Does it contain a certain element
  8. Copy elements in vector to an array
  9. Get Enumeration from this vector
  10. Compare two vectors
  11. Get element from vector
  12. Is vector empty
  13. Get element index
  14. Remove element from a vector
  15. Retain elements collection c has
  16. Replace element in a vector
  17. Get a sub list from a list
  18. Convert Vector to Array