Java String: copyValueOf() Method
copyValueOf() Method
Contents:
public static String copyValueOf(char[] data)
Equivalent to valueOf(char[]).
Java Platform: Java SE 8
Syntax:
copyValueOf(char[] data)
Parameters:
Name | Description | Type |
---|---|---|
data | the character array. | String |
Return Value: a String that contains the characters of the character array.
Return Value Type: String
Pictorial presentation of Java String copyValueOf() Method
Example: Java String copyValueOf() Method
The following example shows the usage of java String() method.
public class Example {
public static void main(String[] args)
{
// Character array with data.
char[] arr_num = new char[] { '1', '2', '3', '4' };
// Create a String containig the contents of arr_num
// starting at index 1 for length 2.
String str = String.copyValueOf(arr_num, 1, 3);
// Display the results of the new String.
System.out.println("\nThe book contains " + str +" pages.\n");
}
}
Output:
The book contains 234 pages.
public static String copyValueOf(char[] data, int offset, int count)
Equivalent to valueOf(char[], int, int).
Java Platform: Java SE 8
Syntax:
copyValueOf(char[] data, int offset, int count)
Parameters:
Name | Description | Type |
---|---|---|
data | the character array. | String |
offset | initial offset of the subarray. | String |
count | the length of the subarray. | String |
Return Value : a String that contains the characters of the specified subarray of the character array.
Return Value Type: String
Throws:
IndexOutOfBoundsException - if offset is negative, or count is negative, or offset+count is larger than data.length.
Example: Java String copyValueOf() Method
The following example shows the usage of java String() method.
public class Example {
public static void main(String[] arg) {
char[] textArray = { 'w', '3', 'r', 'e', 's', 'o', 'u', 'c', 'o', 'm', ' ', 'j', 'a', 'v', 'a',
'r', 'c','e', '.', 'c', 'o', 'm' };
String text = String.copyValueOf(textArray, 6, 2);
System.out.println();
System.out.println(text);
System.out.println();
}
}
Output:
uc
Java Code Editor:
Previous:contentEquals Method
Next:endsWith Method
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework