Java Example – Convert String to Character Array




Java Tutorial for Beginners
Java Tutorial for Beginners

In this java example we will see how to convert a given String object to an array
of characters.

/**
 * Created by codebind.com.
 */
public class StringToCharacterArray{

    public static void main(String args[]){
        //declare the original String object
        String myString = "Hello World";
        //declare the char array
        char[] stringArray;

        //convert string into array using toCharArray() method of string class
        stringArray = myString.toCharArray();

        //display the array
        for(int index=0; index < stringArray.length; index++)
            System.out.print(stringArray[index]);

    }

}

/*
Output:
Hello World
*/

  





Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*