Full width home advertisement

Post Page Advertisement [Top]

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

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib