Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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
Updated on: 2020-06-26T12:21:40+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements