Java String valueOf(char c) method example

HQ » Java Tutorial » java.lang » String » valueOf(char c) method example
Java String valueOf(char c) method example 2018-02-19T13:12:15+00:00

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 :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.