2 Ways to Convert String to Character Array in Java

Here you will learn about different ways to convert string to character array in java.

1. Using String.toCharArray() Method

We can easily convert string to character array using String.toCharArray() method. It can be done in following way.

 

Output

I   L o v e   J a v a 

 

2. Writing Own Logic

We can also writing our own logic. Each character of string is extracted using String.charAt() method and inserted into the character array.

 

Please comment below if you know any other way to do this.

Leave a Reply

Your email address will not be published. Required fields are marked *