Java.lang Package Classes

Java String - copyValueOf() Method



The java.lang.String.copyValueOf() method returns a string that contains the characters of specified character array.

Syntax

public static String copyValueOf(char[] data)

Parameters

data specify the array of characters.

Return Value

Returns a string that contains the characters of specified array.

Exception

NA.

Example:

In the example below, copyValueOf() method returns a string that contains the characters of specified array.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    char[] data = {'H', 'E', 'L', 'L', 'O'};
    
    String str = String.copyValueOf(data);
    System.out.println(str);   
  }
}

The output of the above code will be:

HELLO

❮ Java.lang - String