Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Convert String to char array example

  1. /*
  2.  * Convert String to char array example. Program to convert String object
  3.  * to array of character.
  4.  */
  5.  
  6. public class StringToCharArray {
  7.  
  8.  public static void main(String args[]){
  9.  
  10.   String str = "Hello world";
  11.  
  12.   //to convert string to char array, use toCharArray method of String
  13.   char[] ch = str.toCharArray();
  14.  
  15.   System.out.println("String converted to char array");
  16.  
  17.   //print char array
  18.   for(int i=0; i< ch.length; i++)
  19.    System.out.print(ch[i] + " ");
  20.    
  21.  
  22.  }
  23. }
Your rating: None Average: 2 (3 votes)
Share this

Post new comment

7 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.