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

In this section, you will get the detailed explanation about the copyValueOf(char[] data, int offset, int count) method of String class. We are going to use copyValueOf(char[] data, int offset, int count) method of String class in Java. The description of

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

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

     

In this section, you will get the detailed explanation about the copyValueOf(char[] data, int offset, int count) method of String class. We are going to use copyValueOf(char[] data, int offset, int count) method of String class in Java. The description of the code is given below for the usage of the method.

Description of the code:

As shown in the example we have taken a byte array to copy the contents to the other string. That is this method creates a new String object with the contents of a character array. Thus in the following program code we have passed the initial offset of the array and length of the array to the copyValueOf() method. Hence we get the following output.

This method returns a String that represents the character sequence in the array specified.

Parameters:
data
- the character array.
offset - initial offset of the subarray.
count - length of the subarray. 

Here is the code of the program: 

public class StrCopyValueOf{
  public static void main(String[] args){
  char[] arr = new char[] { '6''8''5''3' };
  String str = String.copyValueOf(arr, 01);
  System.out.println("The new String contains \"" + str + "\"");
  }
}

Here is the code of the program: 

C:\unique>javac StrCopyValueOf.java

C:\unique>java StrCopyValueOf
The new String contains "6"

C:\unique>

Download this example.