java tutorial - Java Strings copyValueOf() method - java programming - learn java - java basics - java for beginners
![java strings copy value of](https://wikitechy.com/tutorials/java/img/java-images/java-strings-copy-value-of.gif)
Learn java - java tutorial - java strings copy value of - java examples - java programs
Description
Java Strings copyValueOf() method in Java has two different forms:
- public static String copyValueOf (char [] data) - it returns a string which represents a sequence of characters in the specified array.
- public static String copyValueOf (char [] data, int offset, int count) – it is a sequence of characters in a given array.
Syntax
The syntax of the method is:
public static String copyValueOf(char[] data)
(or)
public static String copyValueOf(char[] data, int offset, int count)
click below button to copy the code. By - java tutorial - team
Options
Detailed information about the parameters:
- data is an array of characters;
- offset is the beginning of the displacement of the subarray;
- count is the length of the subarray.
Return value
- In Java, copyValueOf () returns a string containing the characters of the character array.
Sample Code
public class Test {
public static void main(String args[]) {
char[] Str1 = {'H', 'i',' ', 'W', 'i', 'k', 'i', 't', 'e', 'c', 'h', 'y'};
String Str2 = "";
Str2 = Str2.copyValueOf(Str1);
System.out.println("Returned string: " + Str2);
Str2 = Str2.copyValueOf(Str1, 2, 10);
System.out.println("Returned string: " + Str2);
}
}
click below button to copy the code. By - java tutorial - team
Output:
Returned string: Hi Wikitechy
Returned string: Wikitechy