Java.lang.String.copyValueOf() Method


Advertisements


Description

The java.lang.String.copyValueOf(char[] data) method returns a String that represents the character sequence in the array specified.

Declaration

Following is the declaration for java.lang.String.copyValueOf() method

public static String copyValueOf(char[] data)

Parameters

  • data -- This is the character array.

Return Value

This method returns a String that contains the characters of the character array.

Exception

  • NA

Example

The following example shows the usage of java.lang.String.copyValueOf() method.

package com.tutorialspoint;

import java.lang.*;

public class StringDemo {

   public static void main(String[] args) {
  
   // character array
   char[] charArr = { 'J', 'A', 'V', 'A' };

   // returns a String that contains the characters of the character array
   String str = String.copyValueOf(charArr);

   // prints the string 
   System.out.println(str);
   }
}

Let us compile and run the above program, this will produce the following result:

JAVA

java_lang_string.htm

Advertisements