How to convert String to Char Array in java

Java String's toCharArray() method can be used to convert String to char Array in java. It is simplest method to convert String to char Array.

Example:
package org.arpit.java2blog;

public class StringToCharArrayMain {
/*
 * @Author: Aprit Mandliya
 */
 public static void main(String[] args) {
  String str="java2blog";
  char[] charArr=str.toCharArray();
  for (int i = 0; i < charArr.length; i++) {
   System.out.println(charArr[i]);
  }  
 }
}

When you run above program, you will get below output:
j
a
v
a
2
b
l
o
g

Other String Programs are :

String :

    How to reverse String in java How to check if two Strings are angrams Find length of String without using java inbuilt length method Find all substrings of String in java Find First non repeated character in a String Java Program to check Palindrome String Why String is immutable in java Find duplicate characters in String


Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus

 

Java tutorial for beginners Copyright © 2012