Java Vector.toString()

Syntax

Vector.toString() has the following syntax.

public String toString()

Example

In the following code shows how to use Vector.toString() method.


/*w  w  w . j a  va 2  s  .c om*/

import java.util.Vector;

public class Main {
   public static void main(String[] args) {
           
      Vector  vec = new Vector(4);

      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);

      // convert the contents into string
      System.out.println(vec.toString());
                 
   }     
}

The code above generates the following result.