How do I convert string to char array?

Category: java.lang, viewed: 15504 time(s).

Here we have a small class that convert a string literal into array, a character array.

package org.kodejava.example.lang;

public class StringToArrayExample
{
    public static void main(String[] args)
    {
        // We have a string literal that contains the moto of this website.
        String literal = "Kode Java - Learn Java Programming by Examples";
        
        // Now we want to convert or devided it into a small array of char. To
        // do this we can simply used String.toCharArray() method. This method
        // splits the string into an array of characters.
        char[] temp = literal.toCharArray();
        
        // Here we just iterate the char array and print it to our console.
        for (int i = 0; i < temp.length; i++)
        {
            System.out.print(temp[i]);
        }
        
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats