Convert string to char array in Java



The following is our string.

String str = "Tutorial";

Now, use the toCharArray() method to convert string to char array.

char[] ch = str.toCharArray();

Now let us see the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      String str = "Tutorial";
      System.out.println("String: "+str);
      char[] ch = str.toCharArray();
      System.out.println("Character Array...");
      for (int i = 0; i < ch.length; i++) {
         System.out.print(ch[i]+" ");
      }
   }
}

Output

String: Tutorial
Character Array...
T u t o r i a l
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements