toCharArray() String Example

toCharArray() String Example

java.lang.String class comes with toCharArray() String method to convert string to a character array.

The signature is given of toCharArray() String as defined in Java API.

  • public char[] toCharArray(): Returns a character array comprising the string characters as elements.
In the following toCharArray() String is used to get a char array out of string.

toCharArray() String
Output screen of toCharArray() String Example

As each character of string becomes an element of the array, the length of both is same. Observe screenshot.

A similar method exists in String class doing the same job but with a small difference – getChars().

Pass your comments and suggestions on this tutorial "toCharArray() String Example".

Leave a Reply

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