Easy Tutorial
❮ Java File Data Element ❯

Java copyValueOf() Method

Java String Class


The copyValueOf() method has two forms:

-

public static String copyValueOf(char[] data): Returns a String that represents the character sequence in the array specified.

-

public static String copyValueOf(char[] data, int offset, int count): Returns a String that represents the character sequence in the array specified.

Syntax

public static String copyValueOf(char[] data)

or

public static String copyValueOf(char[] data, int offset, int count)

Parameters

-

data -- A character array.

-

offset -- The initial offset of the subarray.

-

count -- The length of the subarray.

Return Value

Returns a String that represents the character sequence in the array specified.

Example

public class Test {
    public static void main(String args[]) {
        char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'r', 'u', 'n', 'o', 'o', 'b'};
        String Str2 = "";

        Str2 = Str2.copyValueOf( Str1 );
        System.out.println("Returned Result: " + Str2);

        Str2 = Str2.copyValueOf( Str1, 2, 6 );
        System.out.println("Returned Result: " + Str2);
    }
}

The above program execution result is:

Returned Result: hello runoob
Returned Result: llo ru

Java String Class

❮ Java File Data Element ❯