Powered by Blogger.

Convert String to Character Array Example

>> Monday, September 12, 2011

To Convert a String into Character we should have some methods to convert.Java having the methods are toCharArray( ) and charAt( ) .By using these we can convert. But in our program by using toCharArray( ) method is enough.

Convert String to Character Array Example This example shows how to convert a given String object to an array of character


Take a class named as 'Str2Char'


public class Str2Char{

public static void main(String args[]){
String str="Welcome to our blog";
//convert string into array using toCharArray() method of string class
char[] ch=str.toCharArray();
//display the array
for(int i=0;i<str.length();i++){
System.out.println(ch[i]);
}
}
}
The Out put for above Program is:


W
e
l
c
o
m
e

t
o

o
u
r

b
l
o
g

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.