Convert Vector to Array

ReturnMethodSummary
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.
StringtoString()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]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.