• Tuesday, September 16, 2014

    Java - Converting Character to String

    How to convert a character to string.

    In Java, character is a data type which use char keyword to make a variable char type, but this character cant by directly type casted to String. Because String is a class.

    To convert character to string, we use Character.toString(char) method.

    Example:

    char myChar='c';
    String myString="";
    myString=Character.toString(myChar);

    Example 2:

    public String charToString(char a)
    {
    return Character.toString(a);
    }

    See Also: Converting String to Integer and vice-versa

    Syed Masoom Rizvi

    Author & Editor

    Hi, This is Syed Masoom Rizvi, who is continue exploring the world of programming ,programming and programming... :)

    0 comments:

    Post a Comment