The copyValueOf() primarily copies the content of a character array into the string. Two variants of this function are available and both are discussed in this article.
Implementation 1 :
Syntax: public static String copyValueOf(char ch) Parameters: ch : The character array. Return Value : This function returns the string with the contents of character array copied
The new copied string is : Astha Tyagi
In the second implementation, the subarray can also be extracted instead of whole array.
Implementation 2 :
Syntax: public static String copyValueOf(char ch, int index, int num) Parameters: ch : The character array. index : The starting position of array from which copy is to start. num : Number of elements that has to be copied. Return Value : This function returns the string with the contents of character array copied
The new copied string is : Astha
Possible application : This function can be used to general copy or extract only prefix or suffix from the string using implementation 2. One possible example can be extracting only the amount from the given “Rs 1000” type of strings which deal with denominations.
The original array is : Rs 1024 The new string is : 1024
This article is contributed by Astha Tyagi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.Lang.Float class in Java
- Java.io.BufferedInputStream class in Java
- Java.io.ObjectInputStream Class in Java | Set 1
- Java.util.BitSet class in Java with Examples | Set 1
- Java.io.File Class in Java
- Java.io.BufferedWriter class methods in Java
- Java.io.DataOutputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 1
- Java.io.InputStream Class in Java
- Java.io.SequenceInputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 2
- Java.io.Console class in Java
- Java.io.FilterOutputStream Class in Java
- Java.io.StringWriter class in Java
- Java.io.CharArrayReader Class in Java
- Java.io.FileInputStream Class in Java
- Java.io.CharArrayWriter class in Java | Set 1
- Java.io.CharArrayWriter class in Java | Set 2
- Java.io.DataInputStream class in Java | Set 1