Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java String-examples String copyValueOf(char[] data, int offset, int count)

Related Tutorials


 
 

Share on Google+Share on Google+

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

Advertisement
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)

     

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.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Related Tutorials

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

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com