How To Convert Char To String In Java?

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!