Search Java Programs

Wednesday, January 20, 2010

Java String valueOf Example

String class valueOf method example.


String class valueOf method example:- This example demonstrates the working of valueOf method. this method returns String representations of all data types values

Syntax:-valueOf(boolean b)

Here is the code:-

 /**
* @(#) ValueOfString.java
* ValueOfString class demonstrates the working of valueOf() method of String class of lang package
* @version 16-May-2008
* @author Rose India Team
*/



public class ValueOfString {
public static void main(String args[]) {

// method converts any data type value in to String type
boolean result = true;
int in = 234;
char ch = 'u';
double dou = 34.86;
float flt = 54.889f;

System.out.println("String represented boolean value: "
+ String.valueOf(result)
+ "\nString represented integer value: " + String.valueOf(in)
+ "\nString represented char value: " + "'"
+ String.valueOf(ch) + "'"
+ "\nString represented double value: " + String.valueOf(dou)
+ "\nString represented float value: " + String.valueOf(flt));

}
}
Output of the program:-
String represented boolean value: true
String represented integer value: 234
String represented char value: 'u'
String represented double value: 34.86
String represented float value: 54.889

No comments:

Post a Comment

Website Design by Mayuri Multimedia