This method is used to converts different types of values into a string. You can convert different type of data value into String data value.
You can convert different types:
- int to string
- convert long to string
- convert boolean to string
- convert character to string
- convert float to string
- convert double to string
- convert char array to string.
Its return type is String. It is the overload method in the String class. It can accept different type of values.
String.valueOf(DataType value);
class ExampleValueOf
{
public static void main(String args[])
{
int intValue = 1;
float floatValue = 1.1f;
double doubleValue = 1.2;
char charValue = 'a';
char charArray[] = {'J','A','V', 'A'};
boolean booleanValue = true;
System.out.println("Converting int to String = "+ String.valueOf(intValue));
System.out.println("Converting float to String = "+ String.valueOf(floatValue));
System.out.println("Converting double to String = "+ String.valueOf(doubleValue));
System.out.println("Converting char to String = "+ String.valueOf(charValue));
System.out.println("Converting char Array to String = "+ String.valueOf(charArray));
System.out.println("Converting boolean to String = "+ String.valueOf(booleanValue));
}
} Output:
Converting int to String = 1
Converting float to String = 1.1
Converting double to String = 1.2
Converting char to String = a
Converting char Array to String = JAVA
Converting boolean to String = true
