The method toCharArray()
returns an Array
of chars after converting a String into sequence of characters. The returned array length is equal to the length of the String and the sequence of chars in Array matches the sequence of characters in the String.
public char[] toCharArray()
Example: toCharArray() method
In this example we are converting a String into array of chars using toCharArray() method.
public class CharArrayExample{ public static void main(String args[]){ String str = new String("Welcome to BeginnersBook.com"); char[] array= str.toCharArray(); System.out.print("Content of Array:"); for(char c: array){ System.out.print(c); } } }
Output:
Content of Array:Welcome to BeginnersBook.com
Leave a Reply