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.

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 :