Java String copyValueOf Example
String class CopyValueOf method example
String class CopyValueOf method example:- This example demonstrates the working copyValueOf() method. this method returns sequence of characters of char array variables as String values
Syntax:- copyValueOf(char[] data)
Here is the code:-
/**
* @(#) CopyValueOfString.java
* CopyValueOfString class demonstrates the working of copyValueOf() method of String class of lang package
* @version 15-May-2008
* @author Rose India Team
*/
public class CopyValueOfString {
public static void main(String args[]) {
int a[] = { 1, 2, 3 };
char ch[] = { 'u' }, ch1[] = { 'l', 'o', 'o', 'k', 's' }, ch2[] = {
'c', 'o', 'z', 'y' };
// copyValueOf method returns the String representation of the sequence
// of characters from an char array variable
String str = "";
// method here generates complete character sequence of characters of
// char array variable ch
// all sequences of characters have been printed by the method"
System.out.println("Method returns copied value of char array variables: "
+ str.copyValueOf(ch)
+ " "
+ str.copyValueOf(ch1)
+ " " + str.copyValueOf(ch2));
CharSequence heram = "looks cozy ";
System.out.println("Here just index values have been switched by println method: "
+ ch[0] + " " + a[1] + " " + heram);
}
} |
Output of the program:-
Method returns copied value of char array variables: u looks cozy
Here just index values have been switched by println method: u 2 looks cozy
|
|