Home Tutorial Java Corejava Convert string into character array

 
 

Convert string into character array
Posted on: June 29, 2010 at 12:00 AM
This example helps you know how to convert string into character array.

Description:

This tutorial demonstrate how to convert a string into array of char. The toCharArray() method converts string to a new character array.

Code:

public class String2Char {
  public static void main(String[] args) {
    String str = "STRING";
    char[] temp = str.toCharArray();
    for (int i = 0; i < temp.length; i++) {
      System.out.print(temp[i]);
    }
  }
}

Output:

Download this code

Related Tags for Convert string into character array:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.