[ Java Vector](#)
* * *
`toString()` is a built-in method of the `Vector` class in Java, used to return a string representation of the vector. This method is inherited from the `AbstractCollection` class and overridden by the `Vector` class to provide a specific string representation.
### Method Syntax
public String toString()
### Return Value
Returns a string representing all elements in the `Vector` collection.
* * *
## Method Explanation
The `toString()` method of `Vector` returns a string formatted as follows:
1. The string starts with an opening square bracket `[`.
2. Followed by the string representations of all elements, separated by commas `,` and spaces.
3. Ends with a closing square bracket `]`.
### Internal Implementation
This method actually calls the `toString()` implementation of the `AbstractCollection` class, which:
1. Iterates over all elements in the `Vector` using an iterator.
2. Calls the `toString()` method on each element.
3. Concatenates these strings with `", "` separators.
4. Wraps the result with `[` and `]`.
* * *
## Usage Examples
### Basic Example
## Example
import java.util.Vector;
public class VectorToStringExample {
public static void main(String[] args){
// Create a Vector
Vector fruits =new Vector();
// Add elements
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Orange");
// Use the toString() method
String vectorString = fruits.toString();
System.out.println(vectorString);
}
}
#### Output Result
[Apple, Banana, Orange]
### Example with Different Types of Elements
## Example
import java.util.Vector;
public class MixedVectorToString {
public static void main(String[] args){
Vector