All for Joomla All for Webmasters

Java String toCharArray

The java string toCharArray() method converts this string into character array. It returns a newly created character array, its length is similar to this string and its contents are initialized with the characters of this string.

Signature

The signature or syntax of string toCharArray() method is given below:

  1. public char[] toCharArray()

Returns

character array


Java String toCharArray() method example

  1. public class StringToCharArrayExample{
  2. public static void main(String args[]){
  3. String s1=“hello”;
  4. char[] ch=s1.toCharArray();
  5. for(int i=0;i<ch.length;i++){
  6. System.out.print(ch[i]);
  7. }
  8. }}

Output:

hello
PinIt
submit to reddit

Leave a Reply

Top