How To Convert String To Char Array In Java?

This tutorial is simple example for converting a string object into a simple character array. Lets look at the example.

package javabeat.net.core;

public class StringToCharArrayExample {
	public static void main(String[] args) {

		String str = "javabeat";
		char[] strInCharArray = str.toCharArray();

		for (char charVal : strInCharArray) {
			System.out.println(charVal);
		}
	}
}

Output…

j
a
v
a
b
e
a
t

 

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*