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

String.valueOf() method - Here, you will learn how to convert any type of value like integer, float, etc to string using String.valueOf(), method which is a built-in method of String class.


This is a predefined (in-built) function of String class; it returns string value of any type of value.

Consider the program:

Given different type of values and we have to convert and print them in string format.

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));  


Complie: javac
Run: java ConvertIntoString


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    

Java String Programs »



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.