Javatpoint Logo
Javatpoint Logo

Java String toCharArray()

The java string toCharArray() method converts this string into character array. It returns a newly created character array, its length is similar to this string and its contents are initialized with the characters of this string.


Internal implementation


Signature

The signature or syntax of string toCharArray() method is given below:


Returns

character array


Java String toCharArray() method example

Test it Now

Output:

hello

Java String toCharArray() Method Example 2

Let's see one more example of char array. It is useful method which returns char array from the string without writing any custom code.

Output:

Char Array length: 21
Char Array elements: 
W
e
l
c
o
m
e
 
t
o
 
J
a
v
a
t
p
o
i
n
t




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA