Monday, 7 May 2012

Java String toString Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
 */


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

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...