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 email@example.com. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java Deprecated API Scanner tool (jdepscan) in Java 9 with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.concurrent.Phaser class in Java with Examples
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples