Java String copyValueOf() Method
You are Here:
Java String copyValueOf()
The copyValueOf()
method copies an array of characters to the string.
Note: This method does not append the content in String, instead it replaces the existing string value with the sequence of characters of array.
Example
Java Compiler
public class myClass
{
public static void main(String[] args)
{
char[] myStr1 = {'w', 'i', 'k', 'i', 'm', 'a', 's', 's'};
String myStr2 = "";
myStr2 = myStr2.copyValueOf(myStr1, 0, 8);
System.out.print("Returned String: " + myStr2);
}
}
Output
Returned String: wikimass
Syntax
public static String copyValueOf(char[] data, int offset, int count)
Parameter Values
Value | Type | Explanation |
---|---|---|
data | Required | Specifies the char array. |
offset | Required | Specifies the start index of the char array. |
count | Required | Specifies the length of the char array. |
Return Value
Value | Explanation |
---|---|
Number | Returns the characters of the char array. |
StringIndexOutOfBoundsException | This error occurs when any of the following condition satisfied.
|
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.
We are working to cover every Single Concept in Java.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.