You are here:   HomeJava ProgrammingJava ArrayString split() in Java Example
by Dinesh Thakur Category: array

toCharArray():-This method is a predefined method of String present in lang package.It used to convert a String into array of character.

Syntax:-public char[] toCharArray()

Algorithm for toCharArray() in java:


step 1: read string s1

step 2: create a character array c[]=sl.toCharArray()

step 3: initialize i=0

step 4: repeat through step-6 while (i < s1.length)

step 5: print (byte)c[i]

step 6: i=i+ 1

step 7: Exit

Here is the Java Example for toCharArray() in java:

import java.util.Scanner;

public class toCharArray
              public static void main(String args[])
                           Scanner s=new Scanner(;
                           System.out.print("Enter the String : ");
                           String s1=s.nextLine();
                           char c[]=s1.toCharArray();
                                 for(int i=0;i<s1.length();i++)
                                              System.out.println(c[i]+" = "+(byte)c[i]);

toCharArray() in java

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.

What's New and Popular

Popular Article