Java String valueOf(char[] data) method example

HQ » Java Tutorial » java.lang » String » valueOf(char[] data) method example
Java String valueOf(char[] data) method example 2018-02-19T13:12:46+00:00

java.lang.String valueOf(char[] data)

Description :

This java tutorial shows how to use the valueOf(char[] data) method of String class of java.lang package. This method returns a string representation of the character array data. It takes a copy of the character array data thus if the char array will be changed later, the value assigned as a result of calling this method will not be changed.

Method Syntax :

public static String valueOf(char[] data)

Parameter Input :

DataType Parameter Description
char[] data The character array method parameter we are interested to get the String equivalent

Method Returns :

The method valueOf(char[] data) returns a String object which is the String representation of char[] data.

Compatibility Version :

Since the beginning

Exception :


Discussion :

The java method, String valueOf(char[] data) should be accessed statically thus we should do the following String.valueOf(char[] data). This is basically one way to print a character array.

Java Code Example :

This java example source code demonstrates the use of valueOf(char[] data) method of String class. On this java code, we just declare a character array, and then we have printed the return String of method valueOf(). As you would noticed on the code, we have reinitialize the data character array into new values to prove our postulate that any change later on our array will not change the initial String value extracted in invoking valueOf. This is because we take a copy of the string equivalent of character once we invoked the method valueOf().

There’s an interesting method we have used, the String.toCharArray() to convert a String into character array.

Sample Output :

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

java string indexOf-char-array method example

java string indexOf-char-array method example

Exception Scenario :

Not Applicable

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.