string.valueOf()

String.valueOf(var) valueOf() to get string output from other types of variables.
Here are some examples with output.
boolean my_status=true;
String str=String.valueOf(my_status);

System.out.println(str);// true
System.out.println(str.getClass().getName());// java.lang.String
We created one boolean variable first.
In second line we used valueOf() to get string out and printed the value.
In last line we checked the type of variable by using getClass().

Using integer

int my_int=45;
System.out.println(my_int+21); // 66
String str1=String.valueOf(my_int);
System.out.println(str1+"21"); //4521
System.out.println(str1.getClass().getName());// java.lang.String
First we declared one integer variable my_int=45. Printed the value by adding 21, since my_int is an integer, we can add 21 to this.
We created one string variable str1 and stored the string of my_int by using valueOff(). Now we have used string addition ( not integer ) and printed 4521. We also checked the variable type by using getClass().

Using char

char my_char='Z';

String str=String.valueOf(my_char);
System.out.println(str); // Z
System.out.println(str.getClass().getName());// java.lang.String

Using float

float my_float=45.23f;

String str=String.valueOf(my_float);
System.out.println(str); // 45.23
System.out.println(str.getClass().getName());// java.lang.String

Using double

double my_double=45.23;

String str=String.valueOf(my_double);
System.out.println(str); // 45.23
System.out.println(str.getClass().getName());// java.lang.String

Using char array

char my_char[]= {'p','l','u','s'};

String str=String.valueOf(my_char);
System.out.println(str); // plus
System.out.println(str.getClass().getName());// java.lang.String

Using Long

long  my_long= 45L;

String str=String.valueOf(my_long);
System.out.println(str); // 45
System.out.println(str.getClass().getName());// java.lang.String


All String functions


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer