toCharArray : The method toCharArray(), coverts a string into a sequence of characters or character array. It returns a newly created character array.
Syntax: public char[] toCharArray()
Example: toCharArray() method to reverse a string.
package JavaPkg;
public class String_Reverse {
public static void main(String[] args) {
String str="Java is a simple language";
char[] c=str.toCharArray();
for(int i=c.length-1; i>=0; i--){
System.out.print(c[i]);
}
}
}
Output: egaugnal elpmis a si avaJ
Syntax: public char[] toCharArray()
Example: toCharArray() method to reverse a string.
package JavaPkg;
public class String_Reverse {
public static void main(String[] args) {
String str="Java is a simple language";
char[] c=str.toCharArray();
for(int i=c.length-1; i>=0; i--){
System.out.print(c[i]);
}
}
}
Output: egaugnal elpmis a si avaJ
No comments:
Post a Comment