How to copy the content of an Array of characters into a given String using the copyValueOf() method
Coding River
How to copy the content of an Array of characters into a given String using the copyValueOf() method
In this video, we will talk about the Java copyValueOf() method, which is used to copy an Array of characters to a given String. When copying the content of the Array of characters into the String, the method will replace the existing String value with the sequence of characters of the Array. • In this first example, I will show you how to use this copyValueOf() method, to copy the whole Array to the String String str = “I love programming”;
Char[] array = {‘C’ , ‘O’ , ‘D’ , ‘I’ , ‘N’ , ‘G’};
Now let’s call our method str = str.copyValueOf(array); System.out.println(value); The result in the console will show : CODING
• In the second example, I will show you how to use the copyValueOf() method, to copy only specified characters to a given String using specified offset and count values String str = “I love programming”;
Char[] array = {‘C’ , ‘O’ , ‘D’ , ‘I’ , ‘N’ , ‘G’};
Now let’s call our method String value = str.copyValueOf(array , 2 , 4); Let’s note here that the parameter 2 represents the index position from where the method will have to start copying from the array, and the parameter 4 represents the number of characters to be copied System.out.println(value); The result in the console will show : DING
#codingriver #java #programming ... https://www.youtube.com/watch?v=OK8lBJY_bD4
11585382 Bytes