Java/J2EE and SOA (348 Blogs) Become a Certified Professional
AWS Global Infrastructure

Programming & Frameworks

Topics Covered
  • C Programming and Data Structures (16 Blogs)
  • Comprehensive Java Course (4 Blogs)
  • Java/J2EE and SOA (345 Blogs)
  • Spring Framework (8 Blogs)
SEE MORE

How To Convert Char To String In Java?

Published on Aug 14,2019 1.8K Views

23 / 29 Blog from Java Programs

This article will help you explore a concept that is hard to notice but holds immense value in the programming world, I am referring to Converting Char To String In Java. Following pointers will be covered in this article,

The need to convert a char to string arises often while writing a program in java. There are multiple methods by which it can be implemented, some of which are:

  • By using String.valueOf(char) method of String class
  • By using Character.toString(char) method of Character class

Moving on with this article on Char to string in Java

Using String.valueOf(char ch):

This method of String class can be used to convert a specified char to a String. Char is accepted as an argument, and the string equivalent of the argument is returned.

public class CharToString{  
public static void main(String args[]){  
//given char
char character = 'S';
//char to string conversion
String string = String.valueOf(character);  
//displaying the string
System.out.println("String after conversion : "+string);    
}a
}

Output:
String after conversion: S

Moving on with this article on Char to string in Java

Using Character.toString(char ch):

This method of the Character class can also be used to convert the specified character to a string.

 
public class CharToString{  
public static void main(String args[]){  
// char charcater with the value 'Q'
char character = 'Q';
//char to String using toString() method
String string = Character.toString(character);  
//Value of the string after conversion is "Q"
System.out.println("String after conversion : "+string);    
}
}

Output:
String after conversion : Q

Java provides the user with efficient ways to convert a char to a string with ease.

Thus we have come to an end of this article. If you wish to learn more, check out the Java Training by Edureka, a trusted online learning company. Edureka’s Java J2EE and SOA training and certification course is designed to train you for both core and advanced Java concepts along with various Java frameworks like Hibernate & Spring.

Got a question for us? Please mention it in the comments section of this blog and we will get back to you as soon as possible.

Upcoming Batches For Java Certification Training Course
Course NameDateDetails
Java Certification Training Course

Class Starts on 27th April,2024

27th April

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How To Convert Char To String In Java?

edureka.co