Share on Google+Share on Google+

Convert string into character array

Advertisement
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

Advertisements

Posted on: June 29, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.