java.lang.String valueOf(char c)

Description :

This java tutorial shows how to use the valueOf(char c) method of String class of java.lang package. This method returns a string representation of char data type.

Method Syntax :

public static String valueOf(char c)

Parameter Input :

DataType Parameter Description
char c method parameter which we are interested to get the string equivalent

Method Returns :

The String valueOf() method with argument char returns a new String object.

Compatibility Version :

Since the beginning

Exception :


Discussion :

The string valueOf(char c) method is simply to get a String equivalent of char method parameter. This method be statically accessed which means we should call the method like String.valueOfvalueOf(char c).

Java Code Example :

This example source code demonstrates the use of valueOf(char c) of String class. We have used the the toCharArray method to convert String into an array of element. We then use the for each loop to iterate through our character array to print the value of each character of our char array.


 * Java example source code to get the value of char data type

public class StringValueOfChar {

	public static void main(String[] args) {

		// declare a sample string value
		String strValue = "William";
		// convert strValue to character array
		char[] values = strValue.toCharArray();
		// for each element on char array
		for(char c:values){
			// print the String value of char c



Sample Output :

Running the valueOf() method example source code of String class will give you the following output

java string indexOf char method example

java string indexOf char method example

Exception Scenario :


Suggested Reading List :

References :