Sunday 3 April 2011

How to Convert String to Character in java Array Example

  1. /*
  2. Convert String to Character Array Example
  3. */
  4. public class StringToCharacterArrayExample {
  5. public static void main(String args[]){
  6. //declare the original String object
  7. String strOrig = "Hello World";
  8. //declare the char array
  9. char[] stringArray;
  10. //convert string into array using toCharArray() method of string class
  11. stringArray = strOrig.toCharArray();
  12. //display the array
  13. for(int index=0; index < stringArray.length; index++)
  14. System.out.print(stringArray[index]);
  15. }
  16. }

  1. /*
  2. Output of the program would be :
  3. Hello World
  4. */

No comments:

Post a Comment