.valueOf()

shlokPrajapati60053717094 total contributions
Published Oct 31, 2022
Contribute to Docs
The .valueOf()
method returns the string representation of a given value.
Syntax
String.valueOf(value)
The .valueOf()
method is static and is called directly from the String
class.
The value
parameter can be one of the following data types:
int
long
float
double
boolean
char
Example
The following is an example of the .valueOf()
method being applied to values of different data types:
// Main.javapublic class Main {public static void main(String[] args) {// Concatenating an integer with stringint x = 20;String str = "22";System.out.println(String.valueOf(x) + str);// String representation of boolean argumentboolean b = true;System.out.println(String.valueOf(b));// Concatenating string with floatfloat f = 4.66f;System.out.println(str + String.valueOf(f));// Char to Stringchar ch = 'A';System.out.println(String.valueOf(ch));}}
This will produce the following output:
2022true224.66A
All contributors
- shlokPrajapati60053717094 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.