java String

Java String toCharArray() Code With Examples

Table of Contents

Program

public class StringToCharArray 
{
	public static void main(String args[]) 
	{
		String s1 = "venkatesh";
		char[] ch = s1.toCharArray();
		for (int i = 0; i < ch.length; i++) 
                {
			System.out.print(ch[i]);
		}
	}
}

Output

venkatesh

Description

public char[] toCharArray()

Converts this string to a new character array.

Returns:

a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.