How to convert char to String in Java
Published: July 11, 2009 , Updated: January 20, 2010 , Author: mkyong
Here’s a simple program to demonstrate how to convert a Char to a String by using Character.toString() in Java.
public class ConvertCharToString{ public static void main(String [] args){ String website= "http://www.mkyong.com"; System.out.println(website.charAt(11)); String temp = Character.toString(website.charAt(11)); if("m".equals(temp)){ System.out.println("match"); } } }
Output
m match
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
this example seems more to be for converting strings to char and why are throwing in the if statment? just confuses the issue
“website.charAt(11)” will return a char and later use “Character.toString()” to convert char to String.
The if statement is used to show that the char is converted into string and can be used for string compare.