How To Convert Char To String In Java?

SHARE & COMMENT :

This post highlights a simple example to demonstrates how to convert a char datatype to a string object. Lets look at the example program.

package javabeat.net.core;

public class CharToStringExample {
	public static void main(String args[]) {
		String str = "javabeat";

		// convert a String object to char
		char charVal = str.charAt(3);
		System.out.println(charVal);

		// convert char back to String object
		String convertStr = Character.toString(charVal);

		//Check if it matches with the char
		if ("a".equals(convertStr)) {
			System.out.println("Value Matching");
		}
	}
}

Output

a
Value Matching

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better