Java Program to Convert Any Type of Value to String Value Using String.ValueOf() Method

You are currently viewing Java Program to Convert Any Type of Value to String Value Using String.ValueOf() Method

Java program to convert any type of value to string value using String.valueOf() method

class ConvertIntoString
{
	public static void main(String args[])
	{
		//define different type of values
		int intVal=120;
		float floatVal=12.34f;
		double doubleVal=2345.0d;
		boolean booleanVal=true;

		System.out.println("After converting into string");
		
		//printing values in string format 
		System.out.println("String value of intVal: "+ String.valueOf(intVal));
		System.out.println("String value of floatVal: "+ String.valueOf(floatVal));
		System.out.println("String value of doubleVal: "+ String.valueOf(doubleVal));
		System.out.println("String value of booleanVal: "+ String.valueOf(booleanVal));  
	}
}

Output

Complie: javac ConvertIntoString.java
Run: java ConvertIntoString

Output

After converting into string
String value of intVal: 120
String value of floatVal: 12.34
String value of doubleVal: 2345.0
String value of booleanVal: true    

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply