Vector class toString() method example
Returns a string representation of this Vector, containing the String representation of each element.
Vector class toString() method example. This example shows you how to use toString() method.This method Returns a string representation of this Vector, containing the String representation of each element.
Here is the code:-
/*
* @Program that Returns a string representation of this Vector, containing the
String representation of each element.
* ToString.java
* Author:-RoseIndia Team
* Date:-26-May-2008
*/
import java.util.*;
public class ToString {
public static void main(String[] args) {
//Creating Vector
Vector v = new Vector();
//Adding elements in the vector
v.add("G");
v.add("I");
v.add("R");
v.add("I");
v.add("S");
v.add("H");
//Returns a string representation of this Vector, containing the String
//representation of each element.
String s = v.toString();
System.out.println("Elements of the String are: ");
//Displaying the element stored in the String
System.out.println(s);
}
} |
Output of the program:-
Elements of the String are:
[G, I, R, I, S, H] |
|