Java String toString Example
String class toString method example.
String class toString method example:- This example demonstrates the working of toString method. this method returns String representations of all primitive data
Syntax:-toString()
Here is the code:-
/**
* @(#) ToStringString.java
* ToStringString class demonstrates the working of toString() method of String class of lang package
* @version 16-May-2008
* @author Rose India Team
*/
public class ToStringString {
public static void main(String args[]){
//this method toString() converts all data a String representaion
//method converts all primitive values in to String type
int in = 123456;
String str = Integer.toString(in);
System.out.println("String represented integer value: " + str);
//similarly
long value = 8768655;
System.out.println("String represented long value: " + Long.toString(value));
}
} |
Output of the program:-
String represented integer value: 123456
String represented long value: 8768655 |
|