Java Vector toString() Method Tutorial

In this section, we will learn what the Vector toString() method is and how to use it in Java.

What is Java Vector toString() Method?

The Java Vector toString() method is used to return the string representation of the elements in a vector object.

Java Vector toString() Method Syntax:

public String toString()

toString() Method Parameters:

The method does not take an argument.

toString() Method Return Value:

The return value of this method is the string representation of each element in the target vector object.

toString() Method Exceptions:

The method does not throw an exception.

Example: using Vector toString() method

import java.util.Vector; 
public class Main {

    public static void main(String[] args){
        
        Vector <String> vector = new Vector<>();
        vector.add("Jack");
        vector.add("Omid");
        vector.add("Ellen");
        vector.add("John");

        System.out.println(vector.toString());
    }
}

Output:

[Jack, Omid, Ellen, John]
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies