.copyValueOf()
Anonymous contributor
Anonymous contributor3071 total contributions
Anonymous contributor
Published Jul 26, 2021Updated Sep 3, 2021
Contribute to Docs
Returns a string with characters copied from an array.
Syntax
string.copyValueOf(char[] data, int offset, int count)
data
(required): An array of characters to be copied from.offset
(optional): The index of the first character to be copied.count
(optional): The number of characters to be copied.
Example 1
Copy all characters from the charactersArray
array to the copiedCharacters
string:
class CopyAllCharacters {public static void main(String[] args) {String copiedCharacters = "This string will be replaced with copied characters.";char[] charactersArray = {'a','b','c','d','e'};System.out.println(copiedCharacters.copyValueOf(charactersArray));// Output: abcde}}
Example 2
Copy two characters from the array, starting at index 4
:
class SpecificCharactersToCopy {public static void main(String[] args) {String copiedCharacters = "This string will be replaced with copied characters.";char[] charactersArray = {'a','b','c','d','e','f','g','h','i'};System.out.println(copiedCharacters.copyValueOf(charactersArray, 4, 2));// Output: ef}}
All contributors
- Anonymous contributorAnonymous contributor3071 total contributions
- robgmerrill124 total contributions
- christian.dinh2476 total contributions
- Anonymous contributor
- robgmerrill
- christian.dinh
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.